开发者

can't get proper xpath Query for retrieving an image from a webpage

I'm creating a rss service using C# and one of the website that we retrieve rss news from it doesn't have direct link to its images but if we go to their directlink pages we can find a picture by the help of firebug and using "XPATH" feature in firebug I can get a XPATH query for that particular picture but it seems that xpathquery is not valid because I have checked its xpathquery with : HtmlAgilityPack and also yahoo YQL

here is the xpath that I retreive from firebug :

//body
  /form
   /table[2]
    /tbody
     /tr[2]
      /td
       /table
        /tbody
         /tr
          /td
           /table
            /tbody
             /tr
              /td
               /img

and here is my YQL

select * 
from html 
where url="http://isna.ir/ISNA/PicView.aspx?Pic=Pic-1718372-1&Lang=P" 
   开发者_JS百科   and xpath='//body
                  /form
                   /table[2]
                    /tbody
                     /tr[2]
                      /td
                       /table
                        /tbody
                         /tr
                          /td
                           /table
                            /tbody
                             /tr
                              /td
                               /img'

this the website I want to retrieve images from it :

http://isna.ir/ISNA/PicView.aspx?Pic=Pic-1718372-1&Lang=P

since my Xpath ability is too weak and I know only few things about it I have to rely on tools such as firebug ... actually I know only firebug that return the xpath from selected html tag

so I have two question here :

1-would you please write me the correct xpath or advice me how to write a correct one?

2-is there any other tools such as firebug to showing the xpath corresponding of html tags?

regards.


I've got my answer : HtmlAgilityPack doesn't suppoer [tbody] and [html] tag inside xpathQuery so I've rewritten my query like :

//*[@id='Table2']/tbody/tr/td/table/tr/td/img

or

//body/form/table[2]/tr[2]/td/table/tr/td/table/tr/td/img

and here is what I've got from tracing HtmlAgilityPack

/html[1]/body[1]/table[2]/tr[2]/td[1]/table[1]/tr[1]/td[1]/table[1]/tr[1]/td[1]/img[1]

as all of above codes are correct for HtmlAgilityPack

and FYI there is another pluging for firebug called firepath which will give you concise query.

regards.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜