Youtube Scraper c# selenium
Youtube Scraper c# selenium
所以我想在 youtube 上抓取以下 link 中的所有 link: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);
所以没有错误显示,但它只抓取 link 中的一个...而不是显示所有 30 个。
您正在遍历具有 vm-video-list
class 的元素,但您需要使用 vm-video-list
class 遍历 ol
列表中的链接:
foreach (IWebElement link in driver.FindElements(By.CssSelector("ol.vm-video-list a.vm-video-title-content")))
{
all.Add(link).GetAttribute("href").ToString());
}
所以我想在 youtube 上抓取以下 link 中的所有 link: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);
所以没有错误显示,但它只抓取 link 中的一个...而不是显示所有 30 个。
您正在遍历具有 vm-video-list
class 的元素,但您需要使用 vm-video-list
class 遍历 ol
列表中的链接:
foreach (IWebElement link in driver.FindElements(By.CssSelector("ol.vm-video-list a.vm-video-title-content")))
{
all.Add(link).GetAttribute("href").ToString());
}