简体   繁体   English

从粘贴的亚马逊网址获取ASIN

[英]Get ASIN from pasted Amazon url

Whether with PHP, Javascript, or using the Amazon Product Advertising API, I don't care... I can use them all. 无论是使用PHP,Javascript还是使用Amazon Product Advertising API,我都不在乎...我可以全部使用它们。 I've already looked around and found a few other questions here that are the same, but they don't have working answers that I can see. 我已经环顾四周,在这里发现了其他几个相同的问题,但是它们没有我能看到的有效答案。

Has anyone managed this? 有人管理过这个吗? Best case, Amazon has added a function to it's API where you can pass them a URL and they return the ASIN and other product information for the page. 最好的情况是,亚马逊在其API中添加了一个功能,您可以在其中向他们传递一个URL,然后它们返回该页面的ASIN和其他产品信息。

I use the following regex on my php based site to affiliate my money links, it might not be perfect, but works pretty well: 我在基于php的网站上使用以下正则表达式来关联我的资金链接,这可能并不完美,但效果很好:

/(?:dp|o|gp|-)\/(B[0-9]{2}[0-9A-Z]{7}|[0-9]{9}(?:X|[0-9]))/

Essentially, it looks for an ASIN or ISBN-like string after one of the following: "dp/", "o/", "gp/", or "-/" to avoid false positives. 本质上,它在以下之一之后寻找类似于ASIN或ISBN的字符串:“ dp /”,“ o /”,“ gp /”或“-/”,以避免误报。 "-/" is possible with older "obidos" formatted links - they still resolve, even though Amazon no longer generates them. 较旧的“ obidos”格式链接可以使用“-/”-它们仍然可以解析,即使Amazon不再生成它们。 It captures only the ASIN/ISBN, so $matches[0] will always contain the correct string (in php). 它仅捕获ASIN / ISBN,因此$ matches [0]将始终包含正确的字符串(在php中)。 Not tested on non-US links. 未经美国以外的链接测试。 I haven't looked into it, the ASIN formats or the url patterns might be different. 我没有研究过,ASIN格式或url模式可能不同。

The challenge is that Amazon URLs aren't of a single format, there are various kinds, depending on the kind of identifier used and the kind of product. 挑战在于,Amazon URL并非单一格式,而是多种类型,具体取决于所使用的标识符类型和产品类型。

The identifier or key can be an ASIN, or other kinds of product identifiers, eg 标识符或密钥可以是ASIN或其他种类的产品标识符,例如

Valid Values: SKU | 有效值:SKU | UPC | UPC | EAN | EAN | ISBN (US only, when search index is Books). ISBN(仅限美国,当搜索索引为Books时)。 UPC is not valid in the CA locale. UPC在CA语言环境中无效。 (via http://docs.aws.amazon.com/AWSECommerceService/latest/DG/ItemLookup.html ) (通过http://docs.aws.amazon.com/AWSECommerceService/latest/DG/ItemLookup.html

Amazon URLs are often (but not always) of the form http://www.amazon.com/(title of product)/dp/(identifier)/(more random characters not relevant here). Amazon URL通常(但并非总是)采用http://www.amazon.com/ (产品标题)/ dp /(标识符)/(此处不相关的更多随机字符)形式。

In addition to /dp/, you may also see /product/, /ASIN/, /e/. 除了/ dp /,您还可能会看到/ product /,/ ASIN /,/ e /。

Your best bet is to use a regular expression to extract the (identifier), then call the Amazon item lookup API, with all the various types as IdType, passing the identifier as the ItemID, and see what matches. 最好的选择是使用正则表达式提取(标识符),然后调用Amazon项目查找API,并将所有各种类型作为IdType,将标识符作为ItemID传递,然后查看匹配的内容。

Without more detail, or a specific use case, it's impossible to know whether the URL has an ASIN, an ISBN, a SKU, or some other kind of identifier, so you'd have to query against all of them, see what matches, and extract the ASIN from Item Lookup return payload. 没有更多详细信息或特定用例,就不可能知道该URL是否具有ASIN,ISBN,SKU或其他某种标识符,因此您必须查询所有这些标识符,查看匹配的内容,并从“项目查找”返回有效载荷中提取ASIN。

Also - Amazon encourages use of shortened permalinks in the form of: http://amzn.to/xxxxxxx 另外-亚马逊鼓励以以下形式使用缩短的永久链接: http : //amzn.to/xxxxxxx

These are simple HTTP 301 redirections that you'd have to follow in order to get the full link containing the ASIN. 这些是您必须遵循的简单HTTP 301重定向,以获得包含ASIN的完整链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM