【问题标题】:xpath extract YouTube video name? [duplicate]xpath 提取 YouTube 视频名称? [复制]
【发布时间】:2020-03-22 18:37:25
【问题描述】:

如何使用谷歌表格=IMPORTXML()函数从以下h1标签中提取数据?

HTML 标签:

<h1 class="title style-scope ytd-video-primary-info-renderer"><yt-formatted-string force-default-style="" class="style-scope ytd-video-primary-info-renderer">XPath query, IMPORTXML &amp; Google Sheets - Advanced Tutorial</yt-formatted-string></h1>

结果:

XPath query, IMPORTXML & Google Sheets - Advanced Tutorial

【问题讨论】:

    标签: xpath web-scraping google-sheets google-sheets-formula google-sheets-importxml


    【解决方案1】:

    尝试:

    =IMPORTXML("https://www.youtube.com/watch?v=MkgR0SxmMKo","//*[@id='eow-title']")
    

    更多@:https://stackoverflow.com/a/55064665/5632629

    【讨论】:

      【解决方案2】:

      语法很简单,首先是 xml 的 url,然后是 xpath。小心使用单引号和双引号。

      =IMPORTXML("link to your xml file or webpage";"//h1")
      

      或者更具体一点:

      =IMPORTXML("link to your xml file or webpage";"//h1[@class='title style-scope ytd-video-primary-info-renderer']")
      

      编辑:并得到你需要的东西:

      =IMPORTXML("https://www.youtube.com/watch?v=pwZ44kAeiOo";"//span[@class='watch-title']")
      

      【讨论】:

      • 不适用,尝试从此链接提取信息youtube.com/watch?v=pwZ44kAeiOo
      • 好的。使用适当的解决方案编辑帖子。
      • 你能解释一下你为什么使用它 class='watch-title' 我没有在 HTML 代码中找到这个类吗?
      • 当你解析页面时,代码和你在浏览器中看到的有点不同。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-17
      • 1970-01-01
      • 2022-08-17
      • 2014-10-13
      • 2011-09-27
      • 2020-06-26
      相关资源
      最近更新 更多