kejun0566 发表于 2020-3-27 17:10:40

爬取豆瓣首页出错

import urllib.request as ur

response = ur.urlopen("https://www.douban.com/").read()

爬取豆瓣首页 会出错,出错信息如下:

Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\1.py", line 3, in <module>
    response = ur.urlopen("https://www.douban.com/").read()
File "G:\Python\Python37\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
File "G:\Python\Python37\lib\urllib\request.py", line 531, in open
    response = meth(req, response)
File "G:\Python\Python37\lib\urllib\request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
File "G:\Python\Python37\lib\urllib\request.py", line 569, in error
    return self._call_chain(*args)
File "G:\Python\Python37\lib\urllib\request.py", line 503, in _call_chain
    result = func(*args)
File "G:\Python\Python37\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:

请问这是什么意思呢?哪里出错了呢

一个账号 发表于 2020-3-27 17:23:22

加个 headers

qiuyouzhi 发表于 2020-3-27 17:24:07

得加headers
页: [1]
查看完整版本: 爬取豆瓣首页出错