javascript - Python BeautifulSoup html.parser 不工作

标签 javascript python beautifulsoup html-parsing

我有一个脚本可以从亚马逊获取图书信息,该脚本之前运行成功,但今天失败了。我无法弄清楚到底出了什么问题,但我假设它与解析器或 Javascript 相关。我正在使用下面的代码。

from bs4 import BeautifulSoup
import requests

response = requests.get('https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dstripbooks&field-keywords=9780307397980',headers={'User-Agent': b'Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'})
html = response.content
soup = BeautifulSoup(html, "html.parser")
resultcol = soup.find('div', attrs={'id':'resultsCol'})

之前我是在resultcol中获取数据的但现在它是空白的。当我检查html时我看到我正在寻找的标签,即 <div id="resultsCol" class=\'\' > 。但是soup里面没有这段文字。谁能帮我调试这个吗?以前工作得很好,但现在不行了。

最佳答案

删除标题,它应该可以工作。

from bs4 import BeautifulSoup
import requests
response = requests.get('https://www.amazon.com/s/ref=nb_sb_noss?url=search-    alias%3Dstripbooks&field-keywords=9780307397980')
html = response.content
soup = BeautifulSoup(html, "html.parser")
resultcol = soup.find('div', attrs={'id':'resultsCol'})`

关于javascript - Python BeautifulSoup html.parser 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52304522/

相关文章:

python - "undefined symbol: __xmlStructuredErrorContext"从 lxml 导入 etree

javascript - Socket.io/ARI 错误 : Emit Alert

javascript - 如何在一个基本的 HTML 网站中立即将所有 404 链接重定向到主页?

javascript - 通过javascript向图像源添加字母

javascript - 适用于 Windows Phone 的 Cordova Visual Studio 2012 Express : Open External PDF URL

python - Pandas /Python : Groupby and transform against a reference table

python - 如何使用列表理解在 2 个列表之间选择较低的值?

python - 如何使用 Beautiful Soup 的 find() 代替 find_all() 以获得更好的运行时间

python - 在 python 中迭代带有美丽汤的行表

python - 使用 BeautifulSoup 查找所选选项