|
楼主 |
发表于 2017-3-2 11:15:10
|
显示全部楼层
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CsharpHttpHelper;
using System.Net;
using CsharpHttpHelper.Enum;
using System.Text.RegularExpressions;
namespace CsharpHttpHelper_Demo
{
public partial class HttpPost_Demo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//创建Httphelper对象
HttpHelper http = new HttpHelper();
//创建Httphelper参数对象
HttpItem item = new HttpItem()
{
URL = "http://www.ip138.com:8080/search.asp?action=mobile&mobile=18955554444",//URL 必需项
Method = "get",//URL 可选项 默认为Get
//ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
//PostDataType = PostDataType.String,//默认为字符串,同时支持Byte和文件方法
//PostEncoding = System.Text.Encoding.UTF8,//默认为Default,
//Postdata = "a=123&c=456&d=789",//Post要发送的数据
};
//请求的返回值对象
HttpResult result = http.GetHtml(item);
//获取请请求的Html
string html = result.Html;
//获取请求的Cookie
string cookie = result.Cookie;
Regex rg = new Regex("(?<=tdc2>).*?(?=<)"); //获取电话号码
var strresult = rg.Match(html).Groups[0];
Response.Write(strresult);
Regex rg1 = new Regex("(?=<TABLE).*?(?=</TABLE>)"); //获取卡号归属地
var strresult1 = rg1.Match(html).Groups[0];
Response.Write(strresult1);
Regex rg2 = new Regex("(?=<TR class=tdc bgcolor=#EFF1F3>).*?(?=</TR>)"); //获取卡号归属地
var strresult2 = rg2.Match(html).Groups[0];
Response.Write(strresult2);
Regex rg3 = new Regex("(?=<TR class=tdc bgcolor=#EFF1F3>).*?(?=<)"); //获取卡号归属地
var strresult3 = rg3.Match(html).Groups[0];
Response.Write(strresult3);
Regex rg4 = new Regex("(?=<TABLE).*?(?=</TABLE>)"); //获取卡号归属地
var strresult4 = rg4.Match(html).Groups[0];
Response.Write(strresult4);
Regex rg5 = new Regex("(?<=noswap>).*?(?=<)"); //获取手机号段
var strresult5 = rg5.Match(html).Groups[0];
Response.Write(strresult5);
Regex rg6 = new Regex("(?<=tdc2>).*?(?=<a)"); //获取电话号码
var strresult6 = rg6.Match(html).Groups[0];
Response.Write(strresult6);
//Regex rg2 = new Regex("(?<=tdc2>).*?(?=</a)"); //获取邮编
//var strresult2 = rg2.Match(html).Groups[0];
//Response.Write(strresult2);
//Regex rg = new Regex("(?<=\"username\">).*?(?=<)"); //获取用户名
//Regex rg1 = new Regex("(?<=\"z\\s+psw_w\">).*?(?=<)"); //获取密码
//var strresult = rg.Match(html).Groups[0];
//var strresult1 = rg1.Match(html).Groups[0];
//Response.Write(strresult);
//Response.Write(strresult1);
Regex rg0 = new Regex("(?<=\"center\">).*?(?=<)"); //获取卡号归属地
var strresult0 = rg0.Match(html).Groups[0];
Response.Write(strresult0);
//Regex rg = new Regex("/(?<=("+username+"))(?=)/");
//var strresul = rg.Match(html).Groups;
//Response.Write(strresul);
////要Post的数据
//string postdate = "a=123&c=456&d=789";
////将Post数据转为字节数组
//byte[] bytedate = System.Text.Encoding.UTF8.GetBytes(postdate);
////创建Httphelper对象
//HttpHelper http = new HttpHelper();
////创建Httphelper参数对象
//HttpItem item = new HttpItem()
//{
// URL = "http://www.sufeinet.com",//URL 必需项
// Method = "post",//URL 可选项 默认为Get
// ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
// PostDataType = PostDataType.Byte,
// PostdataByte = bytedate
//};
////请求的返回值对象
//HttpResult result = http.GetHtml(item);
////获取请请求的Html
//string html = result.Html;
////获取请求的Cookie
//string cookie = result.Cookie;
////要Post的数据
//string postfile = @"D:\postdata.txt";
////将Post数据转为字节数组
////创建Httphelper对象
//HttpHelper http = new HttpHelper();
////创建Httphelper参数对象
//HttpItem item = new HttpItem()
//{
// URL = "http://www.sufeinet.com",//URL 必需项
// Method = "post",//URL 可选项 默认为Get
// ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
// PostDataType = PostDataType.FilePath,
// Postdata = postfile
//};
////请求的返回值对象
//HttpResult result = http.GetHtml(item);
////获取请请求的Html
//string html = result.Html;
////获取请求的Cookie
//string cookie = result.Cookie;
}
}
}
我是要用你的那个HttpHelper万能框架找那个查电话号码的网站,然后把查询网站的号码归属地还有区号什么的截取出来
<TD width=* align="center" class=tdc2>安徽 马鞍山市</TD>
就是要截取tdc2> </TD>中间的数据 |
|