網頁抓取與https://livingsocial.comasp.net網頁抓取與https://livingsocial.com
目前,我用下面的代碼工作。
此代碼會將用戶authencation要求,但網頁不驗證用戶。
string appURL = "https://livingsocial.com/deals/external_people/login";
string strPostData = String.Format("login={0}&password={1}","[email protected]", "03006403836");
// Setup the http request.
HttpWebRequest wrWebRequest = WebRequest.Create(appURL) as
HttpWebRequest;
//old code
wrWebRequest.ContentType = "application/x-www-form-urlencoded";
wrWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
wrWebRequest.Method = "POST";
wrWebRequest.ContentLength = strPostData.Length;
wrWebRequest.ContentType = "application/x-www-form-urlencoded";
CookieContainer cookieContainer = new CookieContainer();
wrWebRequest.CookieContainer = cookieContainer;
// Post to the login form.
StreamWriter swRequestWriter = new
StreamWriter(wrWebRequest.GetRequestStream());
swRequestWriter.Write(strPostData);
swRequestWriter.Close();
// Get the response.
HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();
// Read the response
StreamReader srResponseReader = new
StreamReader(hwrWebResponse.GetResponseStream());
string strResponseData = srResponseReader.ReadToEnd();
我如何使用cookie容器的下一個請求告訴我與編碼。 – Wasif