2011-04-26 60 views
0

我試圖用YQL - http://www.empireonline.com/search/default.asp?search=Dragonheart(作爲例子)從帝國雜誌網站(電影評論(熱門匹配)表)得到結果,我使用螢火蟲獲取xpath,但它似乎並不想返回結果。這是我正在使用的;從網頁選擇表格數據

select * from html where url='http://www.empireonline.com/search/default.asp?search=cars' and xpath='/html/body/table[3]/tbody/tr[5]/td[2]/table[2]/tbody/tr/td/table[2]/tbody/tr/td/table[2]'

現在,它似乎能夠使用;

select * from html where url='http://www.empireonline.com/search/default.asp?search=cars' and xpath='//table'

但是,這一大堆的數據,我不需要認輸的。

+0

這是一個常見問題**:瀏覽器添加強制性HTML元素到DOM **(如'head'和'tbody'),那些'tbody'不目前在源頭上。 – 2011-04-26 19:26:36

+0

我得到的最好的是以下 - SELECT * FROM HTML WHERE url =「http://www.empireonline.com/search/default.asp?search=cars」and xpath =「// table [3] // table [2] // table [2] // table [2]「 – Garbit 2011-04-26 19:28:00

+0

那麼你的問題解決了嗎?聽起來像你的評論中的XPath完全符合你的需求,對吧? – LarsH 2011-04-26 19:49:18

回答

1

您只需在制定適當的XPath查詢時注意。下面通過首先定位「電影評論(熱門匹配)」段落,然後導航到電影列表來獲得該HTML表格中列出的每個評論的鏈接和名稱。

SELECT href, strong 
FROM html 
WHERE url = 'http://www.empireonline.com/search/default.asp?search=Thor' 
AND xpath = ' 
    //p[.="Film Reviews (Popular Matches)"] 
    /ancestor::table[1] 
    /following-sibling::table[1] 
    //td[2]/a 
' 

Try this query in the YQL console

+0

這是現貨,謝謝薩拉斯! – Garbit 2011-05-03 18:59:37