有没有BeautifulSoup摘录“客户谁买了这个项目也买了”亚马逊产品页面的一部分?

2024-04-26 14:26:11 发布

您现在位置:Python中文网/ 问答频道 /正文

对于任何给定的标题或作者,我正在尝试编写一个脚本(目前)加载Amazon产品页面,并在页面的“购买此项目的客户也购买了”区域中输出项目。我试着把BeautifulSoup指给它看,但我不太清楚它叫什么名字。该部分的h2标题是'a-carousel-heading',我尝试过,但似乎不起作用。我还尝试了包含它的div('div a-column a-span8'),但这似乎也不起作用。你们谁能给我指点一下我要找的区域的确切位置吗?你知道吗

book = raw_input('Enter a book title, or an author\'s name! \n')
products = amazon.search_n(1, Keywords=book, SearchIndex='All')
isbn = products[0].isbn

html = urlopen('http://www.amazon.com/gp/product/', isbn)
soup = BeautifulSoup(html.read(), 'html.parser')
for row in soup.select("div.a-column.a-span8"):
    print(row)

预期输出:

The Basic Works of Aristotle, Aristotle: Selections, etc..

Tags: 项目div区域标题amazonhtmlcolumn页面
1条回答
网友
1楼 · 发布于 2024-04-26 14:26:11

你看到的是标题,而不是旋转木马本身。数据存储在:

<ol class="a-carousel" role="list" aria-busy="false"> 
..

相关问题 更多 >