在页面加载完成后从Web获取响应,包括JavaScript

时间:2016-04-24 18:07:35

标签: c# web-scraping

我想知道如何在加载完成后从网上获得响应,包括JavaScript。

这是我到目前为止所做的:

string url = "https://www.youtube2mp3.cc";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
myHttpWebRequest.Method = "POST";

byte[] data = Encoding.ASCII.GetBytes("name=http://www.youtube.com/watch?v=KMU0tzLwhbE");
myHttpWebRequest.ContentLength = data.Length;

Stream requestStream = myHttpWebRequest.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Close();

HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();

Stream responseStream = myHttpWebResponse.GetResponseStream();

StreamReader myStreamReader = new StreamReader(responseStream, Encoding.Default);
string pageContent = myStreamReader.ReadToEnd();
myStreamReader.Close();
responseStream.Close();
myHttpWebResponse.Close();

0 个答案:

没有答案