java利用chromedriver 抓取数据。版本要绝对对应

public String getGN(String code) {

String url = "https://emweb.securities.eastmoney.com/pc_hsf10/pages/index.html?type=web&code="+code+"&color=b#/hxtc/tcld";

File f = new File("D:\\chromedriver-win64118\\");

if (f.exists()) {

System.setProperty("webdriver.chrome.driver", "D:\\chromedriver-win64118\\chromedriver.exe");

} else {

System.setProperty("webdriver.chrome.driver", "/opt/chromedriver-linux64/chromedriver");

}

// 指定Chrome浏览器核心

// 创建Chrome浏览器驱动

// 配置Chrome选项

ChromeOptions options = new ChromeOptions();

options.addArguments("--headless"); // 无界面运行

options.addArguments("--no-sandbox");

options.addArguments("--disable-gpu");

options.addArguments("--disable-dev-shm-usage");

// 创建Chrome浏览器驱动

WebDriver driver = new ChromeDriver(options);

driver.get(url);

WebDriverWait wait = new WebDriverWait(driver, 3000);

// driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);

// 抓取网页内容

// String pageContent = driver.getPageSource();

List elements = wait

.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className("boardName")));

// 获取标签内容

String all = "";

for (WebElement element : elements) {

String tagContent = element.getText();

all += tagContent+",";

}

return all;

}

你可能感兴趣的:(java,python,开发语言)