我保存了网页的源代码(每个浏览器中的选项);现在我想在以http://
开头的引号之间捕捉所有内容。我怎么能这样做?
答案 0 :(得分:1)
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属性中的链接,而不是纯文本)
答案 1 :(得分:0)
使用正则表达式:
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