本帖最后由 我是MT 于 2015-1-5 14:00 编辑
[C#] 纯文本查看 复制代码 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web;
using System.Windows.Forms;
using CsharpHttpHelper;
namespace 获取天猫搜索结果页内容
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//创建Httphelper对象
HttpHelper http = new HttpHelper();
string keyword = System.Web.HttpUtility.UrlEncode("家装", System.Text.Encoding.GetEncoding("GB2312"));
keyword = keyword.ToUpper();
string url = "http://list.tmall.com/search_product.htm?q=" + keyword;
//string url = "http://www.baidu.com";
//创建Httphelper参数对象
HttpItem item = new HttpItem()
{
URL = url,//URL 必需项
Method = "get",//URL 可选项 默认为Get
ContentType = "text/html",//返回类型 可选项有默认值
Allowautoredirect = true//默认为False就是不根据重定向自动跳转
};
//请求的返回值对象
HttpResult result = http.GetHtml(item);
//获取请请求的Html
string html = result.Html;
//获取请求的Cookie
string cookie = result.Cookie;
//Console.Write(html);
////Console.WriteLine(cookie);
//Console.ReadKey();
textBox_html.Text = html;
}
}
}
取的只是header和footer部分。中间body部分的数据不见了。
好吧,刚才论坛有人说这里的数据用了JSON。
|