在网络浏览器控件中查找文本

发布于 2024-09-28 22:19:24 字数 81 浏览 0 评论 0原文

我有一个网络浏览器控件,已经导航到一个页面。现在我想在页面中搜索特定文本,并滚动到第一个出现的位置。

能够滚动到其他事件是一个好处。

I have a web browser control, already navigated to a page. Now I want to search for a specific text in the page, and scroll to the first occurrence.

Being able to scroll to other occurrences is a bonus.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南街九尾狐 2024-10-05 22:19:24

您可以尝试以下代码:

webBrowser1.Select();
SendKeys.Send("^f");

You can try this code:

webBrowser1.Select();
SendKeys.Send("^f");

星光不落少年眉 2024-10-05 22:19:24

我不知道它是否适用于 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获取页面的源代码,并搜索字符串中的文本,获取其节点名称,并使用进行导航>#。

I don't know if it works in a WebBroswer. We make the broswer(IE/FF/etc) window scroll to some text with the following code:

//source code of http://www.sample.com/sample.html
<html>
...
<span name="aim">KeyWord</span>
...
</html>

If I want the window to scroll to the "KeyWord", simply visit http://www.sample.com/sample.html#aim

Using string document = myWebBrowser.DocumentText to get the source code of the page, and search the text in the string, get its node name, and navigate it using #.

前事休说 2024-10-05 22:19:24

看看这个是否有帮助:

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
}

See this if it helps:

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
}
时光磨忆 2024-10-05 22:19:24

一种方法...

使用 Ctrl + F 键调用 WebBrowser 控件本机的 Find

One way...

Use the Ctrl + F Key to invoke Find, native to the WebBrowser Control?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文