|
楼主 |
发表于 2021-8-12 12:10:47
|
显示全部楼层
可是我申请的url返回的text里面确实是有那些缺失的信息的,我不是在element看的,是在network中看的,然后关于Cookie的代码:
import requests
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36',\
'Cookie':'PHPSESSID=2c9ihsh3epnkmml4734foj0dh0; Hm_lvt_c2c40af8d9153ebf91bb5804a4a5366b=1628734433; HISTORY={video:[{"name":"\u5173\u4E8E\u6211\u8F6C\u751F\u53D8\u6210\u53F2\u83B1\u59C6\u8FD9\u6863\u4E8B\u7B2C\u4E8C\u5B63","link":"http://www.yhdm6.com/acg/5659/","pic":"http://tvax4.sinaimg.cn/large/006sgDEegy1gmddgk8nh8j307i0almyv.jpg"},{"name":"\u6708\u5149\u4E0B\u7684\u5F02\u4E16\u754C\u4E4B\u65C5\u7B2C\u4E00\u5B63","link":"http://www.yhdm6.com/acg/60019/","pic":"http://tvax4.sinaimg.cn/large/006sgDEegy1grxca3z6avj607i0aijss02.jpg"}]}; Hm_lpvt_c2c40af8d9153ebf91bb5804a4a5366b=1628741251'}
resp = requests.get('http://www.yhdm6.com/acg/5659/', headers=headers)
res.encoding = 'utf-8'
print(resp.text)
报错如下:
Traceback (most recent call last):
File "C:\Users\lenovo\Documents\my\Python\mytry.py", line 5, in <module>
resp = requests.get('http://www.yhdm6.com/acg/5659/', headers=headers)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 234, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1230, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1271, in _send_request
self.putheader(hdr, value)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 219, in putheader
_HTTPConnection.putheader(self, header, *values)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1203, in putheader
values[i] = one_value.encode('latin-1')
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 115-130: ordinal not in range(256) |
|