在Web浏览器控件中搜索链接 [英] search for links in a web browser control

查看:72
本文介绍了在Web浏览器控件中搜索链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题,如何找到以以下网址开头的网页的所有链接:在以"http://devvicky.com/page0/"开头的网络浏览器控件中.

例如:以一种形式,我有一个导航到devvicky.com/page0的控件.该页面具有一些从以上字符串开始的链接,但随机分布在该页面上.

WebBrowser1.Document.Links列出了网页的所有链接,但在我的情况下如何继续?

i have a small problem, how do i find all links from a webpage navigated in a web browser control starting with : "http://devvicky.com/page0/".

eg : in a form i have a control which navigates to devvicky.com/page0. This page has some links starting with above string but randomly distributed over the page.

WebBrowser1.Document.Links lists all the links of a webpage but how to proceed in my case??

推荐答案

这是您可以开始使用正则表达式的地方. /> 您可以尝试这样的操作:
This is where you can start using regular expressions.
You can try something like this:
string mySearchPattern = @"


http://(\w+\.?)thedomain\.com^"; if(Regex.IsMatch(inputString, mySearchPattern)) { //do something }
http://(\w+\.?)thedomain\.com^"; if(Regex.IsMatch(inputString, mySearchPattern)) { //do something }


这个正则表达式(我希望)告诉正则表达式引擎是:
输入的字符串是否以http://开头,可以选择包含一个或多个单词字符,后跟一个点,并以thedomain.com结尾?
我说的是我希望这样做是因为我对正则表达式没有太多的经验.
但是,即使这不是一个精确的解决方案,即使您设法驯服正则表达式的基本功能,也永远不会回过头来搜索和替换字符串.
尝试以下链接以获取有关使用正则表达式的完整概述:
www.regular-expressions.info .

希望这会有所帮助,
Andrei


What this regex (i hope) tells the regex engine is:
Does the input string start with http://, optionally contains one or more word characters followed by a dot and ends in thedomain.com?
I''m saying i hope this is what it does because i don''t have a lot of experience with regular expressions.
But even if this is not an exact solution, if you manage to tame even the basic capabilities of regular expressions, you''ll never look back at string searches and replacements.
Try this link for a complete overview of using regular expressions:
www.regular-expressions.info.

Hope this helps,
Andrei


有很多获取链接的方法.
您可以使用正则表达式在DocumentText中进行搜索.

您可以使用Document.Forms遍历所有控件,并仅获取锚标记.

您可以使用GetElementById进行相同的操作.

无论哪种方式,您都可以枚举文档中的链接.
There are quite a few ways to get the links.
You might use a Regular expression to search in DocumentText.

You can loop through all the controls using Document.Forms and get only the anchor tag.

You can use GetElementById to do the same.

Either way you can enumerate the links in your document.


这篇关于在Web浏览器控件中搜索链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆