c#通过WebClient获取的网页内容无法显示在控制台上
try{WebClientwc=newWebClient();varhtmlcode=wc.DownloadString("http://www.anjuke.com/"...
try {
WebClient wc = new WebClient();
var htmlcode = wc.DownloadString("http://www.anjuke.com/");
var regex = new Regex("<div class=\"cities_boxer\">[\\s\\S]*</div>");
if (regex.IsMatch(htmlcode))
{
var div = regex.Match(htmlcode).Groups["div"].Value;
Console.WriteLine(div);
}
Console.ReadLine();
}
catch(WebException webEx) {
Console.WriteLine(webEx.Message.ToString());
}
我是想把获取到的内容用正则表达式筛选一下,请大神帮忙看看哪里出了问题? 展开
WebClient wc = new WebClient();
var htmlcode = wc.DownloadString("http://www.anjuke.com/");
var regex = new Regex("<div class=\"cities_boxer\">[\\s\\S]*</div>");
if (regex.IsMatch(htmlcode))
{
var div = regex.Match(htmlcode).Groups["div"].Value;
Console.WriteLine(div);
}
Console.ReadLine();
}
catch(WebException webEx) {
Console.WriteLine(webEx.Message.ToString());
}
我是想把获取到的内容用正则表达式筛选一下,请大神帮忙看看哪里出了问题? 展开
展开全部
您好,这样的:如果纯粹是下载网页,没必要用socket
WebClient webClient = new
WebClient();
webClient.Credentials =
CredentialCache.DefaultCredentials;
byte[] data = null;
string pageHtml =
"";
try
{
data = webClient.DownloadData(uri);
Encoding loadCode = Encoding.GetEncoding("gb2312");
pageHtml =
loadCode.GetString(data);
}
WebClient webClient = new
WebClient();
webClient.Credentials =
CredentialCache.DefaultCredentials;
byte[] data = null;
string pageHtml =
"";
try
{
data = webClient.DownloadData(uri);
Encoding loadCode = Encoding.GetEncoding("gb2312");
pageHtml =
loadCode.GetString(data);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询