0

I spent three last days to change the proxies of website by C# code and name of website "http://tweetermonitor.apphb.com/" but did not find a very well way to change the proxies from list which i have. Actually my site is extracting the data from websites urls and some of sites are doing blocked my IP address and system fails to extract the data. I have some proxies which I want to change it from the code mean I will place the proxies in database and when my site will be blocked then I will put one proxy and will add in the Webproxy system in Code . I found one code but I did not understand what it mean.

var getHtmlWeb = new HtmlWeb() { AutoDetectEncoding = false, OverrideEncoding = Encoding.GetEncoding("iso-8859-2") };

                WebProxy myproxy = new WebProxy("116.197.134.130:8080", true);

                NetworkCredential cred = (NetworkCredential)CredentialCache.DefaultCredentials;

                var document = getHtmlWeb.Load("http://tweetermonitor.apphb.com/", "POST", myproxy, cred);

Code is running successfully but here what is meaning of Var Document? What is doing?enter image description here Here is the description of What the variable document have. Please help me i need it very badly. Help will be much appreciated. Thanks and hope i will get the help ..

2 Answers2

0

Ill break it down,

// getHtmlWeb is the webclient
var getHtmlWeb = new HtmlWeb() { AutoDetectEncoding = false, OverrideEncoding = Encoding.GetEncoding("iso-8859-2") };

                // This is the WebProxy that you connect through
                WebProxy myproxy = new WebProxy("116.197.134.130:8080", true);
                // from what i believe this pulls the credentials to login to the proxy from the credentialcache
                NetworkCredential cred = (NetworkCredential)CredentialCache.DefaultCredentials;

                // document is the website that has been loaded..
                // "POST", myproxy, cred is used to login to the proxy which then allows you to load the webpage
                var document = getHtmlWeb.Load("http://tweetermonitor.apphb.com/", "POST", myproxy, cred);

For the end part of your question I don't fully understand what you are trying to achieve. But you did request explanation of the code so that is what I have provided.

Offnix
  • 27
  • 6
  • Thanks Offnix for your valuable comment. But I want this actually. I am running the website app which is extracting the data from different websites and some of website check the IP address of mine and block my website tweetermonitor.apphb.com . I just want when the extraction websites will block my site then I will put the new proxies IP : 116.197.134.130 and Port : 8080 . And then my website should work on this give IP (proxy) 116.197.134.130 not mine original IP . I bought more than 20 Proxies for this. This is what I want to achieve through coding.Please help – Arslan Ahmad Jan 20 '17 at 12:15
  • Offnix please help. I have different Json Urls like cncpts.com/products.json and I am getting information in ProductsJsonModel class. I am placing Url string in WebClient and deserialize the URL . I want to know that What will be place from Var document? After getting from proxy. Because I need Url to deserialize the JSON data into class . Here fm=cncpts.com/products.json var jsonString = webClient.DownloadString(fm); ProductsJsonModel Data JsonConvert.DeserializeObject(jsonString)‌​; – Arslan Ahmad Jan 20 '17 at 17:01
  • Find the Answer :) I just want to stream reader to end to read all the page. Thanks for your comments – Arslan Ahmad Jan 20 '17 at 17:37
0

Var Documentation

As per the documentation above var will be complied as a HtmlDocument object because that is what getHtmlWeb.Load() returns. It will basically result in this:

HtmlDocument document = getHtmlWeb.Load("http://.com/", "POST", myproxy, cred);

Depending on what you need you can dot walk in to the objects properties to see the information of the page you have just retrieved. For example the webpages html code is available in this property:

document.DocumentNode.OuterHtml

Nick
  • 1,783
  • 1
  • 15
  • 18
  • Hi Nick as I explained above I am running the website app which is extracting the data from different websites and some of website check the IP address of mine and block my website http://tweetermonitor.apphb.com/ . I just want when the extraction websites will block my site then I will put the new proxies IP : 116.197.134.130 and Port : 8080 . I bought more than 20 Proxies for this. This is what I want to achieve through coding. – Arslan Ahmad Jan 20 '17 at 12:10
  • Hi Nick please comment on this.. I have different Json Urls like http://cncpts.com/products.json and I am getting information in ProductsJsonModel class. I am placing Url string in WebClient and deserialize the URL . I want to know that What will be place from Var document? After getting from proxy. Because I need Url to deserialize the JSON data into class . Here fm=http://cncpts.com/products.json var jsonString = webClient.DownloadString(fm); ProductsJsonModel Data JsonConvert.DeserializeObject(jsonString); – Arslan Ahmad Jan 20 '17 at 16:20
  • Find the Answer :) I just want to stream reader to end to read all the page. Thanks for your comments – – Arslan Ahmad Jan 20 '17 at 17:37
  • @ArslanAhmad Glad i could help get you in the right direction. – Nick Feb 27 '17 at 01:59