2014-02-22 52 views
1

幫助,請下載指定的頁面,並與ID找到她元素=「」登錄」一定需要使用的查詢模塊請求如何加載頁面解析器?

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()

回答

8

你需要傳遞實際html沒有要求:

soup = bs4.BeautifulSoup(html.text)