报错: AttributeError: module 'wsgiref.headers' has no attribute 'items'
代码如下:
from wsgiref import headers
import requests
from bs4 import BeautifulSoup
发起网络连接
response=requests.get("http://www.530p.com/xuanhuan/wulianzuofeng-157643/")
response.encoding=response.apparent_encoding
print(response.status_code)
print(response.text)
soup=BeautifulSoup(response.text,'lxml')
clc=soup.find('div', class_="clc").find_all('a')
for clc in clc :
book_name=clc.text
clc_url=clc['href']
clc_info_html=requests.get('http://www.530p.com/'+clc_url,headers=headers)
clc_info_html.encoding=clc_info_html.apparent_encoding
soup=BeautifulSoup(clc_info_html.text,'lxml')
info=soup.find('div','id=cp_content')
print(info.text)
with open('./小说/'+book_name +'.txt','a',enconding='utf-8') as c:
c.write(info.text)
报错结果如下:
Traceback (most recent call last):
File "c:\Users\Administrator\Desktop\import requests.py", line 20, in
clc_info_html=requests.get('http://www.530p.com/'+clc_url,headers=headers)
File "D:\Program Files\Python310\lib\site-packages\requests\api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "D:\Program Files\Python310\lib\site-packages\requests\api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "D:\Program Files\Python310\lib\site-packages\requests\sessions.py", line 573, in request
prep = self.prepare_request(req)
File "D:\Program Files\Python310\lib\site-packages\requests\sessions.py", line 484, in prepare_request
p.prepare(
File "D:\Program Files\Python310\lib\site-packages\requests\models.py", line 369, in prepare
self.prepare_headers(headers)
File "D:\Program Files\Python310\lib\site-packages\requests\models.py", line 489, in prepare_headers
for header in headers.items():
AttributeError: module 'wsgiref.headers' has no attribute 'items'
需要达成的目的读取并创建小说