后面查账单需要这个cookie键值。连接:http://www.itpub.net/thread-1712534-1-1.html
用WebBrowder控件抓取
不是winform程序,是Asp.net
@0ng_Ching_Tong: 谁跟你说asp.net不能用winform的类?
@上帝之城: 出现了错误,http://bbs.csdn.net/topics/350154823 和这个帖子一样的错误。请看八楼。
@0ng_Ching_Tong:设置线程单元状态为单线程
thread.SetApartmentState(System.Threading.ApartmentState.STA);
thread.start();
@上帝之城: 这个代码写在哪里啊,能给个简单demo吗?大婶
@0ng_Ching_Tong:
using System; using System.Diagnostics; using System.Threading; using System.Web.Mvc; using System.Windows.Forms; namespace InjectWebBrowser.Controllers { public class HomeController : Controller { Form form; WebBrowser browser; Thread thread; bool complated; string html = string.Empty; public string Index() { thread = new Thread(() => { form = new Form(); form.Load += form_Load; browser = new WebBrowser(); browser.Dock = DockStyle.Fill; browser.DocumentCompleted += browser_DocumentCompleted; form.Controls.Add(browser); form.ShowDialog(); }); thread.IsBackground = false; thread.SetApartmentState(ApartmentState.STA); thread.Start(); while (!complated) { Thread.Sleep(1000); } return "<textarea cols='100' rows='20'>" + html + "</textarea>"; } void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { html = browser.DocumentText; Debug.Print(html); complated = true; } void form_Load(object sender, EventArgs e) { browser.Navigate("http://www.baidu.com"); } } }
拿去玩吧,在debug调试模式下成功获取了html代码,debug不调试报“对com组件的调用返回了错误hresult e_fail”,网上有解决方案,自己参考一下吧。