如何加载BeautifulSoup页面解析器? [英] How to load a BeautifulSoup page parser?
问题描述
帮助,请下载指定页面并找到其id为"login"的元素.查询模块请求中必须使用该元素
help please download the specified page and find her element with id =''login ". necessarily need to use for the query module request
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)
错误消息:
回溯(最近通话最近):文件 "C:\ VINT \ OPENSERVER \ OpenServer \ domains \ localhost \ python \ parse_html \ 4_auth \ q.py", 第9行,在 soup = bs4.BeautifulSoup(html)文件"C:\ Python33 \ lib \ site-packages \ bs4__init __.py",第162行,位于 init 中 elif len(markup)< = 256:TypeError:"Response"类型的对象没有len()
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而不是请求:
You need to pass the actual html not the request :
soup = bs4.BeautifulSoup(html.text)
这篇关于如何加载BeautifulSoup页面解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!