Open webpage programmatically and retrieve its html contain as a string

后端 未结 4 1744
梦毁少年i
梦毁少年i 2021-02-09 14:45

I have a facebook account and I would like to extract my friend\'s photo and its personal detail such as \"Date of birth\", \"Studied at\" and so on. I am able to extract the ad

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-09 15:05

    There are in general 2 things you can do here. The first thing you can do is called web scraping. That way you can download the source of the html with the following code:

    var request = WebRequest.Create("http://example.com");
    
    var response = request.GetResponse();
    using (Stream responseStream = response.GetResponseStream())
    {
     StreamReader reader = new StreamReader(responseStream);
     string stringResponse = reader.ReadToEnd();
    }
    

    stringResponse then contains the Html source of the website http://example.com

    However, this is probably not what you want to do. Facebook has an SDK that you can use to download this kind of information. You can read about this on the following pages

    http://developers.facebook.com/docs/reference/api/user/

    If you want to use the FaceBook API then I think it's worth changing your question or asking a new question about this, since it's quite more complicated and requires some autorization and other codings. However, it's the best way since it's unlikely that your code is every going to break and it warrents the privacy of the people you want to get information from.

    For example, if you query me with the api, you get the following string:

    {
       "id": "1089655429",
       "name": "Timo Willemsen",
       "birthday": "08/29/1989",
       "education": [
          {
             "school": {
                "id": "115091211836927",
                "name": "Stedelijk Gymnasium Arnhem"
             },
             "year": {
                "id": "127668947248449",
                "name": "2001"
             },
             "type": "High School"
          }
       ]
    }
    

    You can see that I'm Timo Wilemsen, 21 years old and studyied @ Stedelijk Gymnasium Arnhem in 2001.

提交回复
热议问题