How to get webpage title without downloading all the page source

前端 未结 2 923
小鲜肉
小鲜肉 2020-12-31 23:29

I\'m looking for a method that will allow me to get the title of a webpage and store it as a string.

However all the solutions I have found so far involve downloadin

2条回答
  •  离开以前
    2021-01-01 00:19

    A simpler way to handle this would be to download it, then split:

        using System;
        using System.Net.Http;
    
        private async void getSite(string url)
        {
            HttpClient hc = new HttpClient();
            HttpResponseMessage response = await hc.GetAsync(new Uri(url, UriKind.Absolute));
            string source = await response.Content.ReadAsStringAsync();
    
            //process the source here
    
        }
    

    To process the source, you can use the method described here in the article on Getting Content From Between HTML Tags

提交回复
热议问题