从网页的源代码中提取双引号之间的所有值



我保存了一个网页的源代码(每个浏览器的选项);现在我想捕获以http://开头的引号之间的所有内容。我该怎么做呢?

使用HTML敏捷包

string path = ...
var doc = new HtmlDocument();
doc.Load(path);
var links =
    from e in doc.DocumentNode.Descendants()
    from a in e.Attributes
    where a.Value.StartsWith("http://")
    select a.Value;

(注意它只返回HTML属性中的链接,而不是纯文本)

使用regex:

Dim mc As MatchCollection = Regex.Matches(html, """(http://.+?)""", RegexOptions.IgnoreCase)
For Each m As Match In mc
    Console.WriteLine(m.Groups(1).Value)
Next

html =本页源代码时的输出示例:

http://cdn.sstatic.net/stackoverflow/img/favicon.ico
http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png
http://cdn.sstatic.net/js/stub.js?v=181da36f6419
http://cdn.sstatic.net/stackoverflow/all.css?v=0f0c93534e2b
http://stackoverflow.com/questions/16264292/extract-all-values-between-double-quotes-from-a-webpages-source-code
http://www.gravatar.com/avatar/91d33760d2823fa7cf5c95b41a16fada?s=32&d=identicon&r=PG
http://stackoverflow.com/users/2264365/ajakblackgoat
http://stackexchange.com
http://chat.stackoverflow.com
... etc

最新更新