VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > c#教程 >
  • C#教程之C# extract multiples from web pages based on OpenQA.Selenium.Chrome and ChromeDriver

本站最新发布   C#从入门到精通
试听地址  
https://www.xin3721.com/eschool/CSharpxin3721/

1.Install latest Chrome,Selenium.WebDriver, ChromeDriver

Selenium.WebDriver 3.141.0;

Selenium.WebDriver.ChromeDriver 78.0.3904.7000;

Google Chrome Version 78.0.3904.70 (Official Build) (64-bit);
 

2.

复制代码
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium;
using System.Reflection;


static void WebDriverDemo(string url = "http://www.tieba.com/p/4325046994#!/l/p1")
        {
            ChromeDriver driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
            
            driver.Navigate().GoToUrl(url);
            List<IWebElement> lwe = driver.FindElements(By.CssSelector("img")).ToList();

            List<string> imgsList = new List<string>();
            StringBuilder imgBuilder = new StringBuilder();
            foreach(var img in lwe)
            {                 
                string imgUrl = img.GetAttribute("src");
                imgBuilder.AppendLine(imgUrl);
                imgsList.Add(imgUrl);
            }

            File.WriteAllText("lyf.txt", imgBuilder.ToString());
        }
复制代码

相关教程