【发布时间】:2016-02-13 18:41:27
【问题描述】:
我正在尝试解析:html 中的 id=qualifications。
我遵循了beautifulsoup 文档,并要求提供文档。
我的代码:
import requests
from bs4 import BeautifulSoup
def get_content(url):
if type(url) != str:
print('You need to included a string')
exit()
else:
req = requests.get(url)
soup = BeautifulSoup(req, 'html.parser')
qualifications = soup.find(id="qualifications")
print('Qualifications:\n{}'.format(qualifications))
当我像这样运行它时:
get_content('http://www.somesite.com')
它抛出一个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "parse.py", line 10, in get_content
soup = BeautifulSoup(req, 'html.parser')
File "python3.5/site-packages/bs4/__init__.py", line 176, in __init__
elif len(markup) <= 256:
TypeError: object of type 'Response' has no len()
我怎样才能做到这一点?看起来错误可能是生成的请求的大小大于 256?
【问题讨论】:
-
您需要包含该回溯的 rest。我们不知道实际引发了什么错误。
-
啊,BeautifulSoup 不接受
requests响应对象,不。
标签: python python-3.x beautifulsoup python-requests