求一个正则表达式 我想完成,网页中特定信息的提取,比如我在百度中输入IP,就会得到IP所对应的实际地址,如这样:http://www.baidu.com/s?wd=120.120.120.120我想提取其中的实际地址,要怎么写啊?(C#的更好) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在百度中输入IP:120.120.120.120 会得到这个IP对应实际地址:台湾 现在访问不了百度,jiangshun给解决吧 下面是百度IP查询网页中的部分代码:<p style="line-height:120%;padding:0 0 0 15px;font-size:14px;margin:0px;">您查询的IP:<strong style="color:#c60a00">120.120.120.120</strong> 来自:台湾 此数据由<a href="http://www.ip138.com/" target="_blank">ip138</a>提供<br></p><br>我只想提取其中的"台湾",后面好像也会出现这两个字.要怎么才能完成? try... Regex reg = new Regex(@"(?<=来自:)[^&]+(?= )"); Match m = reg.Match(yourStr); if (m.Success) { richTextBox2.Text = m.Value; } public static string getHTMl(string strIP) { WebClient client = new WebClient(); Byte[] pageData = client.DownloadData("http://www.baidu.com/s?wd="+strIP); string html = Encoding.Default.GetString(pageData); Regex reg = new Regex(@"(?is)(?<=来自:).*(?=( )+此数据由)"); return reg.Match(html).Value.ToString(); }基本可以,顺便请教一下过客, 这个我怎么排除不了啊,出来的结果是:台湾 问一个panel事件的问题??? 如何只允许文本框中输入汉字,字母与空格 Iframe 问题 Ajax自动完成鼠标方向键的问题,请教CSDN的前辈高手们 Distinct与order by的问题 将HMTL的DIV 导出EXCLE 这是怎么了呢? 页面转跳时如何获取Id值。。急求。 取数据库时间应该怎取? 简单问题 DetailsView1的问题 富客户端Silverlight
<p style="line-height:120%;padding:0 0 0 15px;font-size:14px;margin:0px;">您查询的IP:<strong style="color:#c60a00">120.120.120.120</strong> 来自:台湾 此数据由<a href="http://www.ip138.com/" target="_blank">ip138</a>提供<br></p><br>我只想提取其中的"台湾",后面好像也会出现这两个字.要怎么才能完成?
Match m = reg.Match(yourStr);
if (m.Success)
{
richTextBox2.Text = m.Value;
}
public static string getHTMl(string strIP)
{
WebClient client = new WebClient();
Byte[] pageData = client.DownloadData("http://www.baidu.com/s?wd="+strIP);
string html = Encoding.Default.GetString(pageData);
Regex reg = new Regex(@"(?is)(?<=来自:).*(?=( )+此数据由)");
return reg.Match(html).Value.ToString();
}基本可以,顺便请教一下过客, 这个我怎么排除不了啊,
出来的结果是:台湾