Bry*_*yan 20 html python parsing beautifulsoup web-scraping
问题:当我尝试执行脚本时,BeautifulSoup(html, ...)给出错误消息"TypeError:类型'对象的对象'没有len().我尝试将实际的html作为参数传递,但它仍然不起作用.
import requests
url = 'http://vineoftheday.com/?order_by=rating'
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html, "html.parser")
Run Code Online (Sandbox Code Playgroud)
如果您要使用requests.get('https://example.com')来获取 HTML,则应该使用requests.get('https://example.com').text.
小智 6
html.parser 用于忽略页面中的警告:
soup = BeautifulSoup(html.text, "html.parser")
Run Code Online (Sandbox Code Playgroud)