C# extract multiples from web pages based on OpenQA.Selenium.Chrome and ChromeDriver
程序员文章站
2023-04-04 16:39:11
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()); }
下一篇: SpringBoot整合SSM