如何从亚马逊产品页面中提取 asin
how to extract asin from an amazon product page
我有以下网页 Product page,我正在尝试从中获取 ASIN(在本例中为 ASIN=B014MHZ90M),但我不知道如何从该页面获取它.
我正在使用 Python 3.4,Scrapy 和以下代码:
hxs = Selector(response)
product_name = "".join(hxs.xpath('//span[contains(@class,"a-text-ellipsis")]/a/text()').extract())
product_model = hxs.xpath('//body//div[@id="buybox_feature_div"]//form[@method="post"]/input[@id="ASIN"/text()').extract()
这样我没有得到必填字段(ASIN编号)。
1.如何获取商品型号(ASIN)?
2.Is 有一种调试此类代码的方法(我正在使用 PyCharm)。我无法使用调试器,只能使用 运行 它而没有看到 'slow motion'.
中发生了什么
先谢谢大家了。
您可以从 response.url
中提取 B014MHZ90M
response.url.split("/dp/")[1]
response.url.split("/dp/")[1] = B014MHZ90M
response.url.split("/dp/")[0] = http://www.amazon.com
查看您链接的亚马逊页面,ASIN 编号出现在 "Product Details" 部分。使用scrapy shell 下面的xpath
response.xpath('//li[contains(.,"ASIN: ")]//text()').extract()
returns
[u'ASIN: ', u'B014MHZ90M']
对于调试 XPATH,我总是使用 scrapy shell
和 Firebug for Firefox。
您可以从 url 中获取。
r = re.search('www.amazon.com/dp/(.+)/', response.url)
print r.group(1)
我用这个:
re.match("http[s]?://www.amazon.(\w+)(.*)/(dp|gp/product)/(?P<asin>\w+).*", url, flags=re.IGNORECASE)
https://www.amazon.com/gp/seller/asin-upc-isbn-info.html
Amazon Standard Identification Numbers (ASINs) are unique blocks of 10
letters and/or numbers that identify items.
您最好的选择也是最简单的选择是 运行 URL 上的正则表达式,在两个“/”之间寻找 10 个字符的字符串。
'/\w{10}/'
然后您可以简单地从结果中省略“/”。
我有以下网页 Product page,我正在尝试从中获取 ASIN(在本例中为 ASIN=B014MHZ90M),但我不知道如何从该页面获取它.
我正在使用 Python 3.4,Scrapy 和以下代码:
hxs = Selector(response)
product_name = "".join(hxs.xpath('//span[contains(@class,"a-text-ellipsis")]/a/text()').extract())
product_model = hxs.xpath('//body//div[@id="buybox_feature_div"]//form[@method="post"]/input[@id="ASIN"/text()').extract()
这样我没有得到必填字段(ASIN编号)。
1.如何获取商品型号(ASIN)?
2.Is 有一种调试此类代码的方法(我正在使用 PyCharm)。我无法使用调试器,只能使用 运行 它而没有看到 'slow motion'.
中发生了什么先谢谢大家了。
您可以从 response.url
中提取 B014MHZ90Mresponse.url.split("/dp/")[1]
response.url.split("/dp/")[1] = B014MHZ90M
response.url.split("/dp/")[0] = http://www.amazon.com
查看您链接的亚马逊页面,ASIN 编号出现在 "Product Details" 部分。使用scrapy shell 下面的xpath
response.xpath('//li[contains(.,"ASIN: ")]//text()').extract()
returns
[u'ASIN: ', u'B014MHZ90M']
对于调试 XPATH,我总是使用 scrapy shell
和 Firebug for Firefox。
您可以从 url 中获取。
r = re.search('www.amazon.com/dp/(.+)/', response.url)
print r.group(1)
我用这个:
re.match("http[s]?://www.amazon.(\w+)(.*)/(dp|gp/product)/(?P<asin>\w+).*", url, flags=re.IGNORECASE)
https://www.amazon.com/gp/seller/asin-upc-isbn-info.html
Amazon Standard Identification Numbers (ASINs) are unique blocks of 10 letters and/or numbers that identify items.
您最好的选择也是最简单的选择是 运行 URL 上的正则表达式,在两个“/”之间寻找 10 个字符的字符串。
'/\w{10}/'
然后您可以简单地从结果中省略“/”。