arm*_*usk 6 xpath google-sheets web-scraping google-apps-script google-sheets-formula
我想获取此网站上的价格数据(https://tarkov-market.com/item/Pack_of_sugar)
但这不起作用
=IMPORTXML("https://tarkov-market.com/item/Pack_of_sugar","//*[@id='__layout']/div/div[1]/div/div[4]/div[1]/div[2]/div[1]/div[2]")
Run Code Online (Sandbox Code Playgroud)
55,500\xe2\x82\xbd您想要从 Google 电子表格的 URL 中检索价格https://tarkov-market.com/item/Pack_of_sugar并将其放入 Google 电子表格的单元格中。我可以这样理解。如果我的理解是正确的,这个答案怎么样?
\n\n不幸的是,IMPORTXML不能用于这种情况。因为IMPORTXML像这样使用=IMPORTXML("https://tarkov-market.com/item/Pack_of_sugar","//*"),会出现无法从URL中检索值之类的错误。因此,在这种情况下,作为解决方法,我建议使用 Google Apps 脚本作为自定义函数。当使用Google Apps脚本时,可以检索该值。
请将以下脚本复制并粘贴到电子表格的容器绑定脚本中。并请放入=sampleFormula()牢房。这样,就可以将值放入单元格中。
function sampleFormula() {\n const url = "https://tarkov-market.com/item/Pack_of_sugar";\n const html = UrlFetchApp.fetch(url).getContentText();\n return html.match(/price:(.+?)<\\/title>/)[1].trim();\n}\nRun Code Online (Sandbox Code Playgroud)\n\n结果:\n\n\n\n| 归档时间: |
|
| 查看次数: |
20170 次 |
| 最近记录: |