Home > Net >  To obtain an amazon product page how to settle the comments section of the HTML error.
To obtain an amazon product page how to settle the comments section of the HTML error.

Time:11-10

 
Public void the ProcessRequest (HttpContext context)
{
The context. The Response. ContentType="text/plain";
The string url=context. The Request (" url ");
String u="https://www.amazon.com/product-reviews/" + url + "/? PageNumber=1 ";
String url1=GetHTMLCode (u);
The context. The Response. The Write (url1);
}

Protected string GetHTMLCode (string url)
{
HttpWebRequest request=(HttpWebRequest) HttpWebRequest. Create (url);
//using cookies set AllowAutoRedirect attribute to false, is "trying to automatically redirect too many times," the core of the
Request. CookieContainer=new CookieContainer ();
Request. AllowAutoRedirect=false;
WebResponse response=(WebResponse) request. The method GetResponse ();
Stream sm=response. GetResponseStream ();
System. IO. StreamReader StreamReader=new System. IO. StreamReader (sm);
//will flow into the string
A string of HTML=streamReader. ReadToEnd ();
StreamReader. Close ();
Return HTML;
}



Direct access via a browser: https://www.amazon.com/product-reviews/B073WKZPGX/? PageNumber=1 amazon comments section is accessible,




But can't get through the code to obtain the source code, direct access to the authentication code is this piece of code of the page,


How do I change this need, a great god trouble for help to solve the train of thought or code,


CodePudding user response:

Lack of Headers information, the user-agent, such as cookies, encompassing the request, and you can see in the debug page of browser

CodePudding user response:

Recognition for the robot, you can put inside in the request the user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; X64; The rv: 79.0) Gecko/20100101 Firefox/79.0
Bring cookies, what did you watch the browser request header contains F12, and then you also with respect to OK
  • Related