代碼如下:
import requests_html
session = requests_html.HTMLSession()
r = session.get('https://www.baidu.com/')
print(r.text)
報錯內容:
Traceback (most recent call last):
File "C:/Users/41621/.PyCharmEdu2018.3/config/scratches/ht/ht001.py", line 3, in <module>
r = session.get('https://www.baidu.com/')
File "C:\Users\41621\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 543, in get
return self.request('GET', url, **kwargs)
File "C:\Users\41621\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\41621\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 650, in send
r = dispatch_hook('response', hooks, r, **kwargs)
File "C:\Users\41621\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\hooks.py", line 31, in dispatch_hook
_hook_data = hook(hook_data, **kwargs)
File "C:\Users\41621\AppData\Roaming\Python\Python37\site-packages\requests_html.py", line 709, in response_hook
return HTMLResponse._from_response(response, self)
File "C:\Users\41621\AppData\Roaming\Python\Python37\site-packages\requests_html.py", line 660, in _from_response
html_r = cls(session=session)
File "C:\Users\41621\AppData\Roaming\Python\Python37\site-packages\requests_html.py", line 647, in __init__
super(HTMLResponse, self).__init__()
File "C:\Users\41621\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 598, in __init__
self.html = None
AttributeError: can't set attribute
Process finished with exit code 1
剛開始學習,請大神給與幫忙解惑,不勝感激。
uj5u.com熱心網友回復:
self.html = NoneAttributeError: can't set attribute
html = None 那應該是沒爬到東西吧
何必非要用requests_html呢
requests + bs4 也不是很復雜呀
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/181266.html
上一篇:Python代碼轉為exe檔案
下一篇:Python 擲骰子比賽
