我在我的代碼中使用了xpath查詢時遇到了一些麻煩,我想我會拋出這個問題並詢問社區,如果這個查詢實際上是爲其預期目的而正確制定的。如下面的代碼所示,我期望獲取標籤的href屬性中唯一的MP3 URL。這整個HTML的一部分被作爲一個字符串輸入到xpath中。這是適當的xpath查詢語句來獲取此HTML字符串中唯一的MP3 href?
XPath查詢:
$hrefs = $xpath->query("//a[contains(@href,'mp3')]/@href");
送入查詢HTML:
<img class="myclass" title="mytitle" src="http://www.mydomain.com/myfolder/mypic.jpg" alt="myalt" width="552" height="414" />
[be-linked-title-info]
<a title="mytitle" href="https://s3.amazonaws.com/myfolder/published/RJD2+-+SEVEN+LIGHT+YEARS+(INSTRUMENTAL).mp3">Song Name and Artist</a>
The written plain text post entry describing this music track goes here and says blah blah blah
您可以使用螢火蟲或firepath插件的Firefox獲取任何元素的'xpath'網頁上 – RanRag