码迷,mamicode.com
首页 > Windows程序 > 详细

C# extract multiples from web pages based on OpenQA.Selenium.Chrome and ChromeDriver

时间:2019-10-27 16:23:13      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:eal   web   system   uil   message   dem   exec   each   googl   

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());
        }

 

C# extract multiples from web pages based on OpenQA.Selenium.Chrome and ChromeDriver

标签:eal   web   system   uil   message   dem   exec   each   googl   

原文地址:https://www.cnblogs.com/Fred1987/p/11747752.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!