import requests import re url='https://www.biquge66.net/book/29689/20013112.html' headers={ 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36' } response=requests.get(url=url, headers=headers) title=re.findall('<span class="divcss5">(.*?)</span>',response.text)[0] content = re.findall('<div id="booktxt">(.*?)<div class="content">',response.text)[0].replace('</p><p>','\n') print(content)哪有问题
时间: 2024-03-19 12:42:12 浏览: 32
这段代码的缩进有问题,需要对其中的所有代码进行缩进。正确的代码如下:
```
import requests
import re
url='https://www.biquge66.net/book/29689/20013112.html'
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
}
response=requests.get(url=url, headers=headers)
title=re.findall('<span class="divcss5">(.*?)</span>',response.text)[0]
content = re.findall('<div id="booktxt">(.*?)<div class="content">',response.text)[0].replace('</p><p>','\n')
print(content)
```
相关问题
帮我把下面的代码添加请求头:import requests url = 'https://www.tupianzj.com/bizhi/DNmeinv/' html = requests.get(url=url) print(html.text)
import requests
url = 'https://www.tupianzj.com/bizhi/DNmeinv/'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299',
'Referer': 'https://www.tupianzj.com/',
'Accept-Language': 'en-US,en;q=0.9',
'Accept-Encoding': 'gzip, deflate, br',
'Connection': 'keep-alive'
}
html = requests.get(url=url, headers=headers)
print(html.text)
import requests from lxml import etree url="https://www.80142.com/txt/82776.html" html=requests.get(url) print(html)出现requests not get
这个问题可能是因为您没有正确安装 requests 库。请尝试在命令行中使用以下命令安装 requests 库:
```
pip install requests
```
如果您已经安装了 requests 库,那么可能是因为您的代码中出现了其他问题。请检查您的代码是否正确导入了 requests 库,并且 URL 是否正确。另外,您的代码中缺少换行符,请注意格式。下面是您的代码的修改版:
```
import requests
from lxml import etree
url = "https://www.80142.com/txt/82776.html"
html = requests.get(url)
print(html)
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![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)