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
Post a Comment