【发布时间】:2019-04-06 04:31:47
【问题描述】:
这是我的代码,非常简单。由于某种原因,出现上述错误。即使我删除了text = str(html) 并将soup = BeautifulSoup(text, 'html.parser') 替换为soup = BeautifulSoup(html, 'html.parser'),也会出现同样的错误。怎么回事?
with urllib.request.urlopen('https://jalopnik.com/search?q=mazda&u=&zo=-07:00') as response:
html = response.read()
text = str(html)
soup = BeautifulSoup(text, 'html.parser')
print(type(soup))
soup = soup.prettify()
print(soup.find_all('div'))
【问题讨论】:
-
soup = soup.prettify()使soup成为一个字符串。不要用美化的字符串代替你的汤。
标签: python beautifulsoup