【发布时间】:2017-07-30 06:35:01
【问题描述】:
我有一个网络浏览器控件,已经导航到一个页面。现在我想在页面中搜索特定的文本,然后滚动到第一个出现的地方。
能够滚动到其他事件是一种奖励。
【问题讨论】:
标签: c# winforms webbrowser-control
我有一个网络浏览器控件,已经导航到一个页面。现在我想在页面中搜索特定的文本,然后滚动到第一个出现的地方。
能够滚动到其他事件是一种奖励。
【问题讨论】:
标签: c# winforms webbrowser-control
你可以试试这个代码:
webBrowser1.Select(); SendKeys.Send("^f");
【讨论】:
我不知道它是否适用于WebBroswer。我们使用以下代码使浏览器(IE/FF/etc)窗口滚动到一些文本:
//source code of http://www.sample.com/sample.html
<html>
...
<span name="aim">KeyWord</span>
...
</html>
如果我想让窗口滚动到“关键字”,只需访问http://www.sample.com/sample.html#aim
使用string document = myWebBrowser.DocumentText获取页面的源代码,并在字符串中搜索文本,获取其节点名称,并使用#进行导航。
【讨论】:
如果有帮助,请查看:
string PageSource = null;
PageSource = WebBrowser1.Document.Body.InnerHtml();
if (Strings.InStr(PageSource, stringtoFind) > 0) {
...insert an Anchor tag here and then use
WebBrowser1.Navigate to go to the the new URL with the #Anchor tag
} else {
...whatever else
}
【讨论】:
一种方式...
使用 Ctrl + F 键调用 WebBrowser 控件原生的 Find?
【讨论】: