html agility pack url scraping— getting full html link

前端 未结 2 1512
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-21 20:41

Hi I am using html agility pack from the nuget packages in order to scrape a web page to get all of the urls on the page. The code is shown below. However the way it returns to

2条回答
  •  后悔当初
    2021-01-21 21:13

    You can't get the complete url because in the href attribute there isn't the complete url. Example: In your case the page contains relative urls. You need to do this:

    string href = email + n.Attributes["href"].Value;
    

    In this way you will have the full url. The better solution is to check if url is relative or absolute and, if the url is relative, add email at the beginning of the url otherwise no.

提交回复
热议问题