c#硒

c#硒,c#,selenium,selenium-webdriver,youtube,C#,Selenium,Selenium Webdriver,Youtube,所以我想在youtube上抓取以下链接中的所有链接: 这就是我在c#win表单中尝试的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")).GetAtt

所以我想在youtube上抓取以下链接中的所有链接:

这就是我在c#win表单中尝试的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);
IList all=new List();
foreach(driver.FindElements(By.ClassName(“vm视频列表”)中的IWebElement元素)
{
all.Add(element.FindElement(By.TagName(“a”)).GetAttribute(“href”).ToString());
}
writeAllines(“GrabbedLinks.txt”,全部);

所以没有显示错误,但它只获取一个链接。。。而不是全部显示30个。

您正在迭代具有
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());
}

您正在迭代具有
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());
}