www.stackoverflow.com请在那里检查很多href =“link”,
我只想要很好的解决方案。怎么可能收到我的列表框中的所有href链接。
例如在我的网站上显示如下代码。
a href="stackoverflow/questions/31928301/hard-dropping-pieces-in-tetris-like-game" class="question-hyperlink" title="the hard-drop after clearing the ...">tetris-like game
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="Can some explain the right code for
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 })">Will drinking ice food cause weight loss (over a period of time)?
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 })">Get date of next Saturday from a given date
结果只需要收集网址,所以在我的列表框中显示如下
下面的代码只有1个网址,但我是如何收到所有网址的?
代码
HtmlElementCollection bdColl = webBrowser1.Document.GetElementsByTagName("a");
foreach (HtmlElement bdEl in bdColl)
{
if (bdEl.GetAttribute("href").Contains("watch"))
listBox1 = bdEl.OuterHtml.Split('"')[9];
}
答案 0 :(得分:1)
尝试这样的事情
HtmlElementCollection bdColl = webBrowser1.Document.GetElementsByTagName("a");
foreach (HtmlElement bdEl in bdColl)
{
if (bdEl.GetAttribute("href") != null)
listBox1.Add(bdEl.GetArttribute("href"));
}