My importXML + xPath + Soundcloud playlist Not Working

天涯浪子 提交于 2019-12-08 11:18:57

问题


So How To Use importXML By Google Docs Spreadsheet Plus xPath To Help Me Copy Soundcloud Playlist Track Title?

Today I'm looking for a solution on how to copy the Track Title of tracks inside a Soundcloud Playlist/Compilation.

I searched around and discovered importXML function offered by Google Docs Spreadsheet. While digging further about the importXML function, I discovered about xPath.

Great combination! I thought.

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

The Syntax Is

=IMPORTXML(A1,"//div[@class='sc-media-content']/a[@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.

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>

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.

Other Syntax I've Tried

I've tried other syntax too, like;

  • =IMPORTXML(A1,"//div[@class='sc-media-content']/title") As suggested here

  • =IMPORTXML(A1,"//div[@class='sc-media-content']/@title") From an answer found here, though it wasn't an accepted answer.

So what am I doing wrong? How could I copy those soundcloud playlist title to my Google Docs Spreadsheet using xPath?

UPDATE

Based from the answer given by TGH, this should work //div[@class='sc-media-content']/a/text().

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.

So another question might be needed to help solve this one

How to use xPath with JavaScript loaded html elements?


回答1:


Try the following

//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

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



来源:https://stackoverflow.com/questions/24600911/my-importxml-xpath-soundcloud-playlist-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!