c# - VS2017 htmlAgilityPack SelectSingleNode adds [1] to xpath? -


i want pull elements page following code using htmlagilitypack:

htmlweb web = new htmlweb();         var htmldoc = web.load(@"https://www.reddit.com/r/upliftingnews/");          htmlnode getchild = htmldoc.documentnode.selectsinglenode("//html/body/div[4]/div[2]/div/div[1]");           string xpath = getchild.firstchild.xpath + "/div[2]/div/p[1]/a";          var node = htmldoc.documentnode.selectsinglenode(xpath).innertext;          return node; 

this doesn't work since string xpath = "/html[1]/body[1]/div[4]/div[2]/div[1]/div[1]/p[1]/div[2]/div/p[1]/a". [1] added /html, /body , /div, essentially. why? how fix xpath becomes correct?


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -