【问题标题】:Youtube Scraper c# seleniumYoutube Scraper c# selenium
【发布时间】:2015-09-16 03:06:46
【问题描述】:

所以我想在 youtube 上获取以下链接中的所有链接:https://www.youtube.com/my_videos?o=U

这就是我在 c# win form selenium firefox 驱动程序中尝试过的

IList<string> all = new List<string>();
foreach (IWebElement element in driver.FindElements(By.ClassName("vm-video-list")))
{
     all.Add( element.FindElement(By.TagName("a")).GetAttribute("href").ToString());
}
File.WriteAllLines("GrabbedLinks.txt", all);

所以没有显示错误,但它只抓取其中一个链接...而不是显示所有 30 个。

【问题讨论】:

    标签: c# selenium selenium-webdriver youtube


    【解决方案1】:

    您正在迭代具有 vm-video-list 类的元素,但您需要使用 vm-video-list 类迭代 ol 列表中的链接:

    foreach (IWebElement link in driver.FindElements(By.CssSelector("ol.vm-video-list a.vm-video-title-content")))
    {
        all.Add(link).GetAttribute("href").ToString());
    }
    

    【讨论】:

      猜你喜欢
      • 2019-07-16
      • 2020-11-04
      • 2021-12-24
      • 2018-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-11
      • 2021-11-17
      相关资源
      最近更新 更多