欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-05-29 10:57:06
1.Install latest Chrome,Selenium.WebDriver, ChromeDriver Selenium.WebDriver 3.141.0; Selenium.WebDriver.ChromeDriver 78.0.3904.7000; Google Chrome Ver ......

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