How to load a BeautifulSoup page parser?
帮助:请下载指定的页面并找到id=''login'的元素。必须用于查询模块请求
1 2 3 4 5 6 7 8 9 10 11 12 | import pprint import requests import bs4 url = 'http://forum.saransk.ru/' html = requests.get(url) #print(html.text) soup = bs4.BeautifulSoup(html) loginForm = soup.find('form', {'id': 'login'}) pprint.pprint(loginForm) |
错误消息:
Traceback (most recent call last): File
"C:\VINT\OPENSERVER\OpenServer\domains\localhost\python\parse_html\4_auth\q.py",
line 9, in
soup = bs4.BeautifulSoup(html) File"C:\Python33\lib\site-packages\bs4__init__.py", line 162, in init
elif len(markup) <= 256: TypeError: object of type 'Response' has no len()
号
您需要传递实际的HTML,而不是请求:
1 | soup = bs4.BeautifulSoup(html.text) |