0

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?

Community
  • 1
  • 1
GaryP
  • 2,173
  • 1
  • 21
  • 28

1 Answers1

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

TGH
  • 38,769
  • 12
  • 102
  • 135
  • Hm.. I tried it on the page suggested. I did however have to close the div manually before testing. – TGH Jul 06 '14 at 22:44
  • `//div[@class='sc-media-content']/a/text()` should work, based on the testing tool you've posted. Here's what I've found out by the way. When looking at the page's source code, the html block is not there. I mean, the code block that supposed to hold the `div class="sc-media-content` is not in the source code. So it must be loaded by JS, right? – GaryP Jul 06 '14 at 23:06