请帮助下载指定页面并找到其id=''login”的元素。一定需要用于查询模块请求
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 而不是请求:
soup = bs4.BeautifulSoup(html.text)
关于python - 如何加载 BeautifulSoup 页面解析器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21956956/