I am pretty desperate because I canโt figure out how to achieve what I said in the question. I already read a lot of similar examples, but did not find what works in the exact situation. So let's say I have the following code:
<table><tr> <td><a href="url-a">text A</a></td><td><a>id A</a></td><td><a>img A</a></td> <td><a href="url-b">text B</a></td><td><a>id B</a></td><td><a>img B</a></td> <td><a href="url-c">text C</a></td><td><a>id C</a></td><td><a>img C</a></td> </tr></table>
Now I already have a part of url-a. I basically want to know how I can get id A and img A. I'm trying to "find" a string with XPath, but I cannot find a way to make it work. In addition, it is possible that information is generally absent. This is my last attempt (seriously, I have been messing with this for more than 3 hours, trying in many ways):
if (htmlDoc.DocumentNode.SelectSingleNode(@"/a[contains(@href, 'part-url-a')]") != null) string ida = htmlDoc.DocumentNode.SelectSingleNode(@"/a[contains(@href, 'part-url-a')]/following-sibling::a").InnerText;
Well, this is apparently wrong, so I would be very happy if someone could help me here. I would also appreciate it if someone could point me to some Web site that explains XPath in detail and notation / syntax with examples like this. Books are also welcome.
PS: I know that I could achieve my goal without XPath at all with Regex or just with StreamReader in C # and check if each line contains what I need, but a) it is too fragile for my needs, because the code can be cool line-breaks and b) I really want to stay the same, fully adhering to XPath for everything I do in this project.
Thanks in advance for your help!
source share