httpwebrequst post传值抓取页面 正则获取 img System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)"; System.Net.WebResponse response = request.GetResponse(); using(System.IO.Stream resStream = response.GetResponseStream()) { System.IO.StreamReader sr = new System.IO.StreamReader(resStream, encoding); string html =sr.ReadToEnd(); }
string html = Encoding.GetEncoding("GBK").GetString(new System.Net.WebClient().DownloadData("http://www.100to.com/item.htm?id=4608977035")); string title = System.Text.RegularExpressions.Regex.Match(html, "(?is)(?<=<title[^>]*>)((?!</title).)+").Value; //title就是你要的结果。
string html = Encoding.GetEncoding("GBK").GetString(new System.Net.WebClient().DownloadData("http://www.100to.com/item.htm?id=4608977035")); Match m = System.Text.RegularExpressions.Regex.Match(html, @"(?is)<title>(.+)</title.+?<div class=""gallery"">.+?<img.+?src=""([^""]+)"); string title = m.Groups[1].Value;//标题 string imgUrl = m.Groups[2].Value;//图片地址
正则获取 img
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
System.Net.WebResponse response = request.GetResponse();
using(System.IO.Stream resStream = response.GetResponseStream())
{
System.IO.StreamReader sr = new System.IO.StreamReader(resStream, encoding);
string html =sr.ReadToEnd();
}
string title = System.Text.RegularExpressions.Regex.Match(html, "(?is)(?<=<title[^>]*>)((?!</title).)+").Value;
//title就是你要的结果。
Match m = System.Text.RegularExpressions.Regex.Match(html, @"(?is)<title>(.+)</title.+?<div class=""gallery"">.+?<img.+?src=""([^""]+)");
string title = m.Groups[1].Value;//标题
string imgUrl = m.Groups[2].Value;//图片地址