【问题标题】:c#-Windows Form - How find href more link in listbox?c#-Windows Form - 如何在列表框中找到href更多链接?
【发布时间】: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,所以在我的列表框中显示如下

  1. http://stackoverflow/questions/31928301/hard-dropping-pieces-in-tetris-like-game
  2. http://stackoverflow//questions/31931390/when-i-press-the-button-remove-ads-it-doesnt-do-any-thing-in-in-app-purchases
  3. https://unix.stackexchange.com/questions/222368/get-date-of-next-saturday-from-a-given-date
  4. 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


    【解决方案1】:

    试试这样的

    HtmlElementCollection bdColl = webBrowser1.Document.GetElementsByTagName("a");
    foreach (HtmlElement bdEl in bdColl)
    {
         if (bdEl.GetAttribute("href") != null)
                    listBox1.Add(bdEl.GetArttribute("href"));
    }​
    

    【讨论】:

    • 感谢您的帮助,我从这个问题中得到了很好的解决方案。这对我的工作目标很有帮助。
    猜你喜欢
    • 1970-01-01
    • 2011-03-06
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-30
    相关资源
    最近更新 更多