How can i parse the rel=”canonical” tag with URL from a html document?
I want to find the url here:
<link rel="canonical" href="http://stackoverflow.com/questions/2593147/html-agility-pack-make-code-look-neat" />
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Suppose
docis yourHtmlDocumentobject.should get you the
linkelements that have arelattribute. Now iterate:Also, it’s possible to filter links in the SelectNodes call to only get the ones with “canonical”:
doc.DocumentNode.SelectNodes("//link[@rel='canonical']");Not tested code, but you get the idea 🙂