需要去淘宝取点数据回来,但是淘宝的登录做得太蛋疼了。没空去研究它的加密方法。
所以决定用WebBrowser来进行登录,然后再传入HttpWebRequest对象进行数据抓取。
按这个地址 http://www.sufeinet.com/thread-6976-43-1.html
获取到了CookieCollection ,也获取到了UserAgent,
[C#] 纯文本查看 复制代码 void GetAgent(WebBrowser wb) {
object window = wb.Document.Window.DomWindow;
Type wt = window.GetType();
object navigator = wt.InvokeMember("navigator", BindingFlags.GetProperty, null, window, new object[] { });
Type nt = navigator.GetType();
object userAgent = nt.InvokeMember("userAgent", BindingFlags.GetProperty, null, navigator, new object[] { });
this.tb_UA.Text = userAgent == null ? "" : userAgent.ToString();
}
再把它传入获取页面的时候,还是一直跳登录页面,是不是我哪个参数没有设置对?
CookieCollection 我看过了。获取到了43个对象。
[C#] 纯文本查看 复制代码 private void button1_Click(object sender, EventArgs e)
{
HttpHelper helper = new HttpHelper();
HttpItem item = new HttpItem()
{
CookieCollection = cc,
URL = "http://trade.taobao.com/trade/itemlist/list_bought_items.htm",
UserAgent = this.tb_UA.Text,
Referer = "http://www.taobao.com/",
Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/json",
Host = "trade.taobao.com"
};
HttpResult res = helper.GetHtml(item);
this.textBox1.Text = res.StatusCode + " <--> " + DateTime.Now;
this.textBox1.Text = res.Header["Location"];
this.textBox1.Text += res.Html;
}
|