pm: Install-Package HtmlAgilityPack -Version 1.11.12
private void button1_Click(object sender, EventArgs e)
{
string url_base = "https://www.qiushuzw.com/t";
string novel = "21868";
string section = "22173677.html";
string url = string.Format("{0}/{1}/{2}",url_base,novel,section);
HDA.HtmlDocument doc = new HDA.HtmlDocument();
doc.LoadHtml(WebGetter.GetHtmlContent(url));
HDA.HtmlNode node = doc.DocumentNode.SelectSingleNode("//h1");
HDA.HtmlNode nodeContent = doc.DocumentNode.SelectSingleNode("//div[@id='content']");
MessageBox.Show(node.InnerHtml);
MessageBox.Show(nodeContent.InnerHtml);
}
public static string GetHtmlContent(string url, string encoding = "utf8")
{
string result = string.Empty;
try
{
if (!string.IsNullOrEmpty(url))
{
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
Encoding encode = Encoding.GetEncoding("utf-8");
StreamReader reader = new StreamReader(new GZipStream(stream, CompressionMode.Decompress), encode);
result = reader.ReadToEnd();
/*
Char[] read = new Char[256];
int count = reader.Read(read, 0, 256);
while (count>0)
{
string str = new String(read, 0, count);
sb.Append(str);
count = reader.Read(read, 0, 256);
}
*/
reader.Close();
stream.Close();
response.Close();
}
}
catch (Exception ex)
{
throw;
}
return result;
}