我的importXML + xPath + Soundcloud播放列表不起作用 [英] My importXML + xPath + Soundcloud playlist Not Working
问题描述
今天我正在寻找一个如何复制的解决方案Soundcloud播放列表/编辑中曲目的曲目标题。
Today I'm looking for a solution on how to copy the Track Title of tracks inside a Soundcloud Playlist/Compilation.
我搜索并发现了Google Docs Spreadsheet提供的importXML功能。在进一步挖掘 importXML
函数时,我发现了 xPath
。
I searched around and discovered importXML function offered by Google Docs Spreadsheet. While digging further about the importXML
function, I discovered about xPath
.
很棒的组合!我想。
所以我很快就抓住了工具并进行了测试,这太棒了!我提取了一些数据。所以我决定我已经准备好实现该工具并将其与Soundcloud一起使用。
So I quickly get my hands on the tools and tested it, and it's great! I've extracted some data. And so I decided that I'm ready to implement the tool and use it with Soundcloud.
但是当我尝试实现语法时,我收到错误说导入内部错误
But when I tried to implement the syntax, I got an error saying Import Internal Error
=IMPORTXML(A1,"//div[@class='sc-media-content']/a[@title]")
< div class =sc-media-content>
是包含曲目标题的div歌曲,包含在 title
属性的锚标记中。
<div class="sc-media-content">
is the div that holds the Track Title of the song, that is enclosed within an anchor tag with title
attribute.
这是它的html块;
Here is the html block for it;
<div class="sc-media-content">
<a class="soundTitle__title sc-link-dark sc-truncate " href="/seven-lions/velvetine-the-great-divide?in=thedubstepgod/sets/melodic-dubstep-chillstep" title="Velvetine - The Great Divide (Seven Lions Remix)">
Velvetine - The Great Divide (Seven Lions Remix)
</a>
我想要的是什么提取物是 Velvetine - The Great Divide(Seven Lions Remix)
。 A1
是粘贴 Soundcloud播放列表链接
的单元格。
What I'm trying to extract is the Velvetine - The Great Divide (Seven Lions Remix)
. A1
is the cell where the Soundcloud Playlist Link
is pasted into.
我也试过其他语法,比如;
I've tried other syntax too, like;
-
= IMPORTXML(A1,// div [@ class ='sc-media-content'] / title)
建议这里
= IMPORTXML(A1,// div [@ class ='sc-media-content'] / @ title)
从找到的答案 here ,虽然这不是一个公认的答案。
=IMPORTXML(A1,"//div[@class='sc-media-content']/@title")
From an answer found here, though it wasn't an accepted answer.
那我是什么?做错了?如何使用xPath将这些soundcloud播放列表标题复制到我的Google Docs电子表格?
So what am I doing wrong? How could I copy those soundcloud playlist title to my Google Docs Spreadsheet using xPath?
基于答案由 TGH
给出,这应该有效 // div [@ class ='sc-media-content'] / a / text()
。
Based from the answer given by TGH
, this should work //div[@class='sc-media-content']/a/text()
.
但是,问题是我们正在寻找的div块不在源代码中。我在播放列表的页面上输入了查看源代码
,并且div块不存在。我所看到的只是JavaScripts。所以JS正在加载div块/类。
But, the problem is that the div block that we're looking for is not in the source code. I did a view source code
on the Playlist's page and the div block is not there. All I'm seeing is JavaScripts. So JS is loading the div blocks/classes.
如何在JavaScript加载的html元素中使用xPath?
How to use xPath with JavaScript loaded html elements?
推荐答案
请尝试以下
//div[@class='sc-media-content']/a/text()
或者,如果你想从标题中获取它,请执行此操作
Or if you want to grab it from the title do this
//div[@class='sc-media-content']/a/@title
我测试过它在这里似乎工作。粘贴你的html,但必须手动关闭div。
I tested it here and it seems to work. Pasted your html, but had to close the div manually.
http://www.unit-testing.net/Xpath
这篇关于我的importXML + xPath + Soundcloud播放列表不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!