使用python查找amazon类别

2024-09-30 10:36:36 发布

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

我想得到amazon的类别,我计划废弃不用API。 我已经取消了http://www.amazon.com,我已经在Shop By Department下拉列表中抓取了所有的类别和子类别,我创建了一个web服务来完成这项工作,代码就在这里

@route('/hello')
def hello():
    text=list();
    link=list();
    req = urllib2.Request("http://www.amazon.com",
                  headers={"Content-Type": "application/json"})
    html=urllib2.urlopen(req).read()
    soup = BeautifulSoup(html)
    last_page = soup.find('div', id="nav_subcats")
    for elm in last_page.findAll('a'):
        texts = elm.text
        links = elm.get('href')
        links = links.partition("&node=")[2]
        text.append(texts)
        link.append(links)
    alltext=list();
    for i,j in zip(text,link):
        alltext.append({"name":i,"id":j})
    response.content_type = 'application/json'
    print(alltext)
    return dumps(alltext)
run(host='localhost', port=8080, debug=True)

我将category name和category id作为JSON对象传递给我的一个成员,以将其传递给API以获取每个类别的产品列表

它是用文字写的爪哇。这里是密码吗

^{pr2}$

但是,当我将类别id作为BrowseNodeId传递,将类别名称作为关键字和搜索索引传递时,会遇到此错误。在

 For example
     Search Index and Keyword -Amazon Instant Video
     BrowseNodeId-2858778011

The value you specified for SearchIndex is invalid. Valid values include [ 'All','Apparel',...................................reless','WirelessAccessories' ].

我想知道从哪个亚马逊网址我将得到所有的类别和它的浏览节点

谢谢你


Tags: textcomapiidhttpamazonforwww
1条回答
网友
1楼 · 发布于 2024-09-30 10:36:36

我以前从未看过Amazon的API,所以这只是一个猜测,但是根据错误消息,“Amazon即时视频”似乎不是一个有效的搜索索引。仅仅因为它在下拉列表中,并不一定意味着它是一个有效的搜索索引。在

以下是我们的搜索索引列表:http://docs.aws.amazon.com/AWSECommerceService/latest/DG/USSearchIndexParamForItemsearch.html。我不知道它有多新,但“亚马逊即时视频”并没有出现在列表中。错误消息确实包含一个有效搜索索引值的列表,这些值似乎与上面的列表相对应。在

其他区域设置请看这里:http://docs.aws.amazon.com/AWSECommerceService/latest/DG/APPNDX_SearchIndexParamForItemsearch.html

我不认为这本身就是一个编码问题。在

您可能想看看python-amazon-product-api。API可能对您有用,文档可能会给您一些想法。在

相关问题 更多 >

    热门问题