http://192.168.0.180:8082/login.html?phone13975180278&password=f5022bfe1d10735abf7c6e750ae365ae 通过正则取到上面的url地址的后面的phone和password的值, 通过js语法
时间: 2024-04-19 17:24:09 浏览: 19
你可以使用正则表达式和JavaScript来提取URL后面的phone和password的值。下面是一个示例代码:
```javascript
var url = "http://192.168.0.180:8082/login.html?phone=13975180278&password=f5022bfe1d10735abf7c6e750ae365ae";
var regex = /phone=(\d+)&password=([\w]+)/;
var matches = url.match(regex);
var phone = matches[1];
var password = matches[2];
console.log("Phone: " + phone);
console.log("Password: " + password);
```
这段代码会将URL中的phone和password的值提取出来,并打印在控制台上。在上述示例中,phone的值为`13975180278`,password的值为`f5022bfe1d10735abf7c6e750ae365ae`。你可以根据自己的需求修改代码。
相关问题
import requests import re headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'} def baidu(page): num = (page - 1) * 10 url = 'http://www.baidu.com/s?ie=utf-8&medium=0&rtt=1&bsst=1&rsv_dl=news_b_pn&cl=2&wd=meizu&tn=news&rsv_bp=1&rsv_sug3=16&rsv_sug1=6&rsv_sug7=100&oq=&rsv_btype=t&f=8&inputT=5752&rsv_sug4=6599&x_bfe_rqs=032000000000000000004800000000000000000000000008&x_bfe_tjscore=0.080000&tngroupname=organic_news&newVideo=12&goods_entry_switch=1&pn='+ str(num) res = requests.get(url, headers=headers).text baidu(i+1) print("第"+str(i+1)+"页爬取成功") import re p_title = '}"><!--s-text-->(.*?)<!--/s-text--></a></h3><div class=' #提取标题 title=re.findall(p_title,res,re.S) print(title) p_info = 'c-gap-right-xsmall" aria-label=".*?">(.*?)</span><span ' #提取时间 info=re.findall(p_info,res,re.S) print(info) p_href= '<a class="source-link_Ft1ov" href="(.*?)"' #提取网址 href=re.findall(p_href,res,re.S) print(href) p_souce='<span class="c-color-gray" aria-label=".*?">(.*?)</span>' #提取来源 souce=re.findall(p_souce,res,re.S) print(souce) for i in range(len(title)): title[i]=re.sub('<.*?>','',title[i]) #去掉<em>、</em> print(str(i+1)+"."+title[i]+' ('+info[i]+"-"+souce[i]+')') print(" ",href[i])
您的代码中有一些问题需要修改:
1. 在 `baidu` 函数中,递归调用 `baidu` 函数时,应该传入 `page` 参数而不是 `i+1`。
2. 在正则表达式中,如果要匹配 `'` 或 `"` 等特殊字符,需要在前面加上反斜线 `\` 进行转义。
3. 在正则表达式中,应该使用非贪婪模式 `.*?` 代替贪婪模式 `.*`,以避免匹配到多余的内容。
下面是修改后的代码:
```python
import requests
import re
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'
}
def baidu(page):
num = (page - 1) * 10
url = 'http://www.baidu.com/s?ie=utf-8&medium=0&rtt=1&bsst=1&rsv_dl=news_b_pn&cl=2&wd=meizu&tn=news&rsv_bp=1&rsv_sug3=16&rsv_sug1=6&rsv_sug7=100&oq=&rsv_btype=t&f=8&inputT=5752&rsv_sug4=6599&x_bfe_rqs=032000000000000000004800000000000000000000000008&x_bfe_tjscore=0.080000&tngroupname=organic_news&newVideo=12&goods_entry_switch=1&pn=' + str(num)
res = requests.get(url, headers=headers).text
# 在这里可以对 res 进行数据解析和处理
# ...
if page < 5:
baidu(page+1)
print("第"+str(page)+"页爬取成功")
p_title = '}"><!--s-text-->(.*?)<!--/s-text--></a></h3><div class=' #提取标题
title = re.findall(p_title, res, re.S)
print(title)
p_info = 'c-gap-right-xsmall" aria-label="(.*?)">' #提取时间
info = re.findall(p_info, res, re.S)
print(info)
p_href = '<a class="source-link_Ft1ov" href="(.*?)"' #提取网址
href = re.findall(p_href, res, re.S)
print(href)
p_source = '<span class="c-color-gray" aria-label="(.*?)">' #提取来源
source = re.findall(p_source, res, re.S)
print(source)
for i in range(len(title)):
title[i] = re.sub('<.*?>', '', title[i]) #去掉<em>、</em>
print(str(i+1) + "." + title[i] + ' (' + info[i] + " - " + source[i] + ')')
print(" ", href[i])
```
需要注意的是,百度搜索结果的页面结构经常会发生变化,如果您的代码无法正常提取数据,可能需要根据实际情况进行调整。另外,爬虫程序需要遵守网站的爬虫规则,不得过度访问和请求网站,避免对网站造成负担和影响。
树莓派4b使用pip安装paddle时出现错误:python -m pip install paddle -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dirDefaulting to user installation because normal site-packages is not writeable Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple, https://www.piwheels.org/simple Collecting paddle Downloading https://pypi.tuna.tsinghua.edu.cn/packages/55/cf/e4b6b9a54d2f072e4491e34317bf5f5fea260da8a3072e641832dc9ce770/paddle-1.0.2.tar.gz (579 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 579.0/579.0 kB 1.8 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [19 lines of output] Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module> main() File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel return hook(config_settings) File "/tmp/pip-build-env-_506dkis/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=['wheel']) File "/tmp/pip-build-env-_506dkis/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires self.run_setup() File "/tmp/pip-build-env-_506dkis/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 487, in run_setup super(_BuildMetaLegacyBackend, File "/tmp/pip-build-env-_506dkis/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 338, in run_setup exec(code, locals()) File "<string>", line 3, in <module> File "/tmp/pip-install-514wqan3/paddle_7c2bfe27eaa349ecb89b325af305b6fa/paddle/__init__.py", line 5, in <module> import common, dual, tight, data, prox ModuleNotFoundError: No module named 'common' [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip.
这个错误可能是由于缺少一些依赖项或者环境配置不正确导致的。你可以尝试以下几种方法来解决这个问题:
1. 确保你的pip版本是最新的,可以运行 `python -m pip install --upgrade pip` 来更新到最新版本。
2. 确保你的系统中已经安装了必要的依赖项,如gcc、g++、make等。
3. 可以尝试使用conda来安装paddle,具体操作可以参考Paddle官方文档:https://www.paddlepaddle.org.cn/install/quick
4. 如果以上方法都不能解决问题,可以尝试从源码编译PaddlePaddle,具体操作可以参考PaddlePaddle官方文档:https://www.paddlepaddle.org.cn/documentation/docs/zh/install/compile/linux-compile.html
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)