爬豆瓣出错了
>>> import urllib.request>>> response = urllib.request.urlopen('http://www.douban.com')
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
response = urllib.request.urlopen('https://www.douban.com/accounts/login')
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 640, in http_response
response = self.parent.error(
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 569, in error
return self._call_chain(*args)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 502, in _call_chain
result = func(*args)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 418:
这为什么出错呀?豆瓣网站不能爬吗? 被反爬了
这样即可:
import urllib.request
req = urllib.request.Request('http://www.douban.com', headers={'User-Agent': 'Mozilla/5.0'})
response = urllib.request.urlopen(req) 如果在headers参数里加上cookie
应该可以大幅度减少识别度 很多网站没有cookie是不行的 风尘岁月 发表于 2020-8-6 20:04
如果在headers参数里加上cookie
应该可以大幅度减少识别度 很多网站没有cookie是不行的
可以详解一下吗? zltzlt 发表于 2020-8-6 18:59
这样即可:
可以了,感谢! sharank 发表于 2020-8-6 21:14
可以详解一下吗?
找到那个网站1然后network筛选出xhr文件 得到cookie 然后添加进去
页:
[1]