简体   繁体   English

在Windows窗体应用程序中以编程方式单击网页的按钮

[英]Programmatically Clicking on a Web Page's Button in Windows Forms Application

I am working on a project which is Analysis of Papers from Google Scholar. 我正在做一个项目,即Google Scholar中的论文分析。 What I do is basically, parsing the HTML, storing related fields into database etc. However, I am stuck at a point, while I am taking the Titles of the publications, I realized, I am able to get first twenty elements. 我所做的基本上是解析HTML,将相关字段存储到数据库中等等。但是,当我拿到出版物的书名时,我被困在某个地方,我意识到,我能够获得前20个元素。 But, there are sixty papers in related account: 但是,相关帐户中有六十篇论文:

http://scholar.google.com/citations?user=B7vSqZsAAAAJ http://scholar.google.com/citations?user=B7vSqZsAAAAJ

So, I think as a solution, I need to click to the 'show more' button programmatically, so I can have all the Title's, Publication Venue etc. 因此,我认为作为解决方案,我需要以编程方式单击“显示更多”按钮,这样我才能获得所有标题,出版物场地等。

What do you think? 你怎么看? How can I perform that kind of action? 我该如何执行这种动作?

Edit: I checked the 'show more' button, while there is nothing to show as a next page, its html code still remains same. 编辑:我选中了“显示更多”按钮,尽管没有任何内容可以显示为下一页,但其html代码仍然保持不变。 As a solution I can use loop for n times. 作为解决方案,我可以使用循环n次。 However, I am looking for more robust solution. 但是,我正在寻找更可靠的解决方案。 Thank you for your time! 感谢您的时间!

If its this website specifically, there is a simple workaround. 如果专门针对其网站,则有一个简单的解决方法。 Change the query string to what records you want. 将查询字符串更改为所需的记录。

http://scholar.google.com/citations?user=B7vSqZsAAAAJ &cstart=0&pagesize=2000 http://scholar.google.com/citations?user=B7vSqZsAAAAJ&cstart = 0&pagesize = 2000

If it is clicking on a button within a WebBrowser control on a Windows Form Application, then 'Yes' you can do it. 如果单击Windows窗体应用程序上WebBrowser控件内的按钮,则可以。 There are ways of getting more control over identification by using XPath. 有一些方法可以通过使用XPath来更好地控制标识。

(You might need to use Javascript to use XPath for object interactions - since you haven't asked for that, I will assume you don't need it) (您可能需要使用Javascript将XPath用于对象交互-既然您没有要求,我假设您不需要它)

webBrowser.Navigate("http://www.google.com");

//   Or

HtmlElement textElement = webBrowser.Document.All.GetElementsByName("q")[0];
textElement.SetAttribute("value", "your text to search");
HtmlElement btnElement = webBrowser.Document.All.GetElementsByName("btnG")[0];
btnElement.InvokeMember("click");

Or even typing into text boxes with 甚至用

webBrowser1.Document.GetElementById("gs_tti0").InnerText = "hello world";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM