如何从网站自动设置输入字段值,提交然后检索页面结果? [英] How to auto set input field value from a website , submit then retrieve the page result ?
问题描述
我正在网站上工作,这是一种球童,我必须使用网络服务来检索产品的价格,但我没有找到任何人,所以我选择了这个网站http://www.wine-searcher.com/wine-valuation-f.lml [ ^ ]填写品牌名称并按一下按钮提交以编程方式检索结果
我试过这段代码:
I'm working on a website , it's kind of caddy, and I have to use a web service to retrieve the price of the products but I didn't find anyone so I chose this website http://www.wine-searcher.com/wine-valuation-f.lml[^] to fill in a name of a brand and submit with a button then retrieve the result programmatically
I tried this code :
public partial class _Default : System.Web.UI.Page
{
string html;
HtmlDocument doc;
WebBrowser ieBrowser;
Form form;
Thread thrd;
protected void Page_Load(object sender, EventArgs e)
{
thrd = new Thread(new ThreadStart(
delegate
{
Init();
System.Windows.Forms.Application.Run();
}));
//set thread to STA state before starting
thrd.SetApartmentState(ApartmentState.STA);
thrd.Start();
}
private void Init()
{
// create a WebBrowser control
ieBrowser = new WebBrowser();
ieBrowser.Visible = true;
form = new System.Windows.Forms.Form();
form.Width = 1000;form.Height=800;
ieBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
form.Controls.Add(ieBrowser);
form.Visible = true;
ieBrowser.Navigate("http://www.wine-searcher.com/wine-valuation-f.lml");
// set WebBrowser event handls
ieBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(IEBrowser_DocumentCompleted);
}
void IEBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
doc = ((WebBrowser)sender).Document;
doc.GetElementById("wn1_input").InnerText = "William Fevre Les Clos, Chablis Grand Cru, France";
doc.GetElementById("vt1_input").InnerText = "NV";
doc.GetElementById("valButton").InvokeMember("Onclick");
// this is the instruction that doesn't work
TextBox1.Text= doc.GetElementById("value").InnerText;
}
一切正常,我可以在打开的表单中看到我的结果,但我的TextBox不受其影响
请问如何在不使用webBrowser的情况下轻松解决这个问题?
谢谢
everything works in the beggining , I can see my result in the the opened form but my TextBox isn't affected by it
please how can I resolve this or is ther an easily way without using webBrowser ?
Thank you
推荐答案
您是否在ASP.Net站点中加载Windorm控件!
创建Winform项目并添加Web浏览器控件,并且没有带有id值的元素页。我认为你需要value1
更改
Are you loading Windorm controls in ASP.Net Site!
Create Winform project and add web browser control and also there is no element with id value in that page. i think you needvalue1
change
TextBox1.Text= doc.GetElementById("value").InnerText;
to
to
TextBox1.Text= doc.GetElementById("value1").InnerText;
这篇关于如何从网站自动设置输入字段值,提交然后检索页面结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!