[英]Requesting Time Based Values from Amazon's search page
The code I'm using below will return/capture the keyword/phrase suggestions from Amazon's search bar.我在下面使用的代码将从亚马逊的搜索栏中返回/捕获关键字/短语建议。 The problem is that there seems to be time based values in the parameters used to construct the output.
问题是用于构造输出的参数中似乎存在基于时间的值。 Can I use a GET request to obtain the current time based values, or is there a better method?
我可以使用 GET 请求来获取基于当前时间的值,还是有更好的方法? The code below is used in conjunction with JSonParser to get the suggestions.
下面的代码与 JSonParser 结合使用以获取建议。 The result I'm looking for is the output of the code to match the drop down results from the Amazon search bar.
我正在寻找的结果是与亚马逊搜索栏下拉结果相匹配的代码输出。
Option Explicit
Public Sub GetTable()
Dim json As Object, suggestion As Object '< VBE > Tools > References > Microsoft Scripting Runtime
Const SEARCH_TERM As String = "TRAVEL"
Const SEARCH_TERM2 As String = "BOOKS"
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "https://completion.amazon.com/api/2017/suggestions?session-id=141-0042012-2829544" & _
"&customer-id=&request-id=7E7YCB7AZZM1HQEZF2G1&page-type=Search&lop=en_US&site-variant=" & _
"desktop&client-info=amazon-search-ui&mid=ATVPDKIKX0DER&alias=aps&b2b=0&fresh=0&ks=76&" & _
"prefix=" & SEARCH_TERM & "&event=onKeyPress&limit=11&fb=1&suggestion-type=KEYWORD&suggestion-type=" & _
"WIDGET&_=1556820864750", False
.setRequestHeader "User-Agent", "Mozilla/5.0"
.send
Set json = JsonConverter.ParseJson(.responseText)("suggestions")
End With
For Each suggestion In json
Debug.Print suggestion("value")
Next
End Sub
Those params values can be removed except the session-id.除了 session-id 之外,这些 params 值可以被删除。 They are actually cookies values.
它们实际上是 cookie 值。 For the session-id you can generate a value for far into the future and that should last for a while.
对于 session-id,您可以为将来生成一个值,该值应该持续一段时间。
Option Explicit
Public Sub GetTable()
Dim json As Object, suggestion As Object, suggestions As Scripting.Dictionary '< VBE > Tools > References > Microsoft Scripting Runtime
Const SEARCH_TERM As String = "TRAVEL"
Const SEARCH_TERM2 As String = "BOOKS"
Set suggestions = New Scripting.Dictionary
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "https://completion.amazon.com/api/2017/suggestions?session-id=999-5000000-8000000" & _
"&customer-id=&request-id=&page-type=Search&lop=en_US&site-variant=" & _
"desktop&client-info=amazon-search-ui&mid=ATVPDKIKX0DER&alias=aps&b2b=0&fresh=0&ks=76&" & _
"prefix=" & SEARCH_TERM & "&event=onKeyPress&limit=11&fb=1&suggestion-type=KEYWORD&suggestion-type=" & _
"WIDGET&_=", False
.setRequestHeader "User-Agent", "Mozilla/5.0"
.send
Set json = JsonConverter.ParseJson(.responseText)("suggestions")
End With
suggestions(json(1)("widgetItems")(1)("metadata")("text")) = vbNullString
For Each suggestion In json
suggestions(suggestion("value")) = vbNullString
Next
Dim key As Variant
For Each key In suggestions.keys
Debug.Print key
Next key
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.