【发布时间】:2015-08-11 01:08:52
【问题描述】:
www.stackoverflow.com 请在那里查看很多 href="link",
我只是想要好的解决方案。如何在我的列表框中收到所有 href 链接。
例如在我的网站中显示如下代码。
a href="stackoverflow/questions/31928301/hard-dropping-pieces-in-tetris-like-game" class="question-hyperlink" title="清除...">俄罗斯方块后的硬降- 类似游戏a href="stackoverflow//questions/31931390/when-i-press-the-button-remove-ads-it-doesnt-do-any-thing-in-in-app-purchases" class="question-hyperlink" title="能否解释一下正确的代码 a href="https://physics.stackexchange.com/questions/199602/will-drinking-ice-cold-water-and-eating-cold-food-cause-weight-loss-over-a-peri" class= "js-gps-track" data-gps-track="site.switch({ item_type:8, target_site:151 }); posts_hot_network .click({ item_type:2, location:8 })">会喝冰食导致减肥(在一段时间内)? a href="https://unix.stackexchange.com/questions/222368/get-date-of-next-saturday-from-a-given-date" class="js-gps-track" data-gps-track ="site.switch({ item_type:8, target_site:106 }); posts_hot_network.click({ item_type:2, location:8 })">从给定日期获取下周六的日期
结果只需要收集的url,所以在我的列表框中显示如下
- http://stackoverflow/questions/31928301/hard-dropping-pieces-in-tetris-like-game
- http://stackoverflow//questions/31931390/when-i-press-the-button-remove-ads-it-doesnt-do-any-thing-in-in-app-purchases
- https://unix.stackexchange.com/questions/222368/get-date-of-next-saturday-from-a-given-date
- https://physics.stackexchange.com/questions/199602/will-drinking-ice-cold-water-and-eating-cold-food-cause-weight-loss-over-a-peri
下面的代码只有 1 个 url,但我是如何收到所有 url 的?
代码
HtmlElementCollection bdColl = webBrowser1.Document.GetElementsByTagName("a");
foreach (HtmlElement bdEl in bdColl)
{
if (bdEl.GetAttribute("href").Contains("watch"))
listBox1 = bdEl.OuterHtml.Split('"')[9];
}
【问题讨论】:
标签: c# regex split webbrowser-control