久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

基于selenium-java封裝chrome、firefox、phantomjs實(shí)現(xiàn)爬蟲

瀏覽:24日期:2022-08-21 18:37:40

2017年一直以來(lái)在公司負(fù)責(zé)爬蟲項(xiàng)目相關(guān)工程,主要業(yè)務(wù)有預(yù)定、庫(kù)存、在開發(fā)中也遇到很多問(wèn)題,隨手記錄一下,后續(xù)會(huì)持續(xù)更新。

chrome、firefox、phantomjs插件安裝和版本說(shuō)明 基于selenium-java封裝chrome、firefox、phantomjs實(shí)現(xiàn)爬蟲

項(xiàng)目下載地址

maven版本說(shuō)明

<!-- +++|selenium|+++ --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.5.1</version> </dependency> <!-- +++|phantomjsdriver|+++ --> <dependency> <groupId>com.github.detro.ghostdriver</groupId> <artifactId>phantomjsdriver</artifactId> <version>1.1.0</version> </dependency>

chrome插件配置

下載地址:chromedriver下載地址選擇本地系統(tǒng)對(duì)應(yīng)的chrome版本安裝,工程下面有一個(gè) 對(duì)應(yīng)的目錄是:Plugin/chromedriver_win32.zip,對(duì)應(yīng)chrmoe版本是Supports Chrome v60-62

直接運(yùn)行項(xiàng)目中示例

public class ChromeTest {public static void main(String[] args) { WebDriver webDriver = null; try { webDriver = WebDriverUtil.createChromeWebDriver('D:webdrvierchromedriver.exe');//修改路徑 webDriver.get('https://www.baidu.com/'); System.out.println(webDriver.getTitle()); } catch (Exception e) { e.printStackTrace(); } finally { if (webDriver != null) { webDriver.close(); } }}}

chrome配置插件是最簡(jiǎn)單的,linux上面只需要把插件換成linux版本即可

firefox

下載插件地址:geckodriver下載地址,選擇本地系統(tǒng)對(duì)應(yīng)的firefox版本安裝,工程下面有一個(gè) 對(duì)應(yīng)的目錄是:Plugin/geckodriver-v0.18.0-win64.zip,對(duì)應(yīng)firefox版本是Firefox Setup 50.0(64位)、其他版本沒(méi)有測(cè)試過(guò)

firefox下載地址、selenium-java版本和geckodriver版本更新迭代不一致,導(dǎo)致在搭建環(huán)境時(shí)很容易出現(xiàn)一系列問(wèn)題。

直接運(yùn)行項(xiàng)目中示例

public class FireFoxTest { public static void main(String[] args) { WebDriver webDriver = null; try { webDriver = WebDriverUtil.createFirefoxWebDriver('D:webdrvierFirefoxgeckodriver_18.exe'); webDriver.get('https://book.douban.com/tag/'); Set<String> tagSet = new HashSet<>(); //獲取豆瓣標(biāo)簽 List<WebElement> divWebElement = webDriver.findElements(By.cssSelector('#content > div > div.article > div:nth-child(2) > div')); for (WebElement webElement : divWebElement) {List<WebElement> aWebElement = webElement.findElements(By.cssSelector('a'));for (WebElement element : aWebElement) { tagSet.add(element.getText());} } System.out.println(tagSet); //點(diǎn)擊小說(shuō)標(biāo)簽 WebElement webElement = webDriver.findElement(By.cssSelector('#content > div > div.article > div:nth-child(2) > div:nth-child(1) > table > tbody > tr:nth-child(1) > td:nth-child(1) > a')); webElement.click(); System.out.println(webDriver.getTitle()); } catch (Exception e) { e.printStackTrace(); } finally { if (webDriver != null) {webDriver.quit();webDriver.close(); } } }}

phantomjs

下載插件地址phantomjs插件地址1、phantomjs插件地址2、下載有些慢。phantomjs是沒(méi)有界面的,所以只需要下載插件即可。

直接運(yùn)行項(xiàng)目中示例

public class PhantomjsTest {public static void main(String[] args) { WebDriver webDriver = null; try { webDriver = WebDriverUtil.createPhantomjsWebDriver('D:/webdrvier/phantomjs-1.9.8-windows/phantomjs.exe'); webDriver.get('https://www.baidu.com/'); System.out.println(webDriver.getTitle()); } catch (Exception e) { e.printStackTrace(); } finally { if (webDriver != null) { webDriver.close(); } }}}

到此這篇關(guān)于基于selenium-java封裝chrome、firefox、phantomjs實(shí)現(xiàn)爬蟲的文章就介紹到這了,更多相關(guān)selenium java封裝爬蟲內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 欧美自拍网 | 久久精品免费看 | 91在线资源 | 亚洲国产成人在线 | 国产99久久久久久免费看农村 | 欧美精品成人一区二区三区四区 | 国产成人综合一区二区三区 | 日韩欧美精品一区二区三区 | 日韩精品专区 | 久久久激情视频 | 国产成人精品久久二区二区 | 日本福利网站 | 日韩一级免费在线观看 | 国产精品一码二码三码在线 | 偷拍自拍亚洲欧美 | 最新中文字幕在线 | 日韩超级毛片 | 亚洲国产高清在线 | 男人的天堂久久 | 国产高清一区二区三区 | 人人做人人澡人人爽欧美 | 成人午夜影院 | 成人免费视频网站在线观看 | 午夜窝窝 | 久久免费精品 | 四虎新网站 | 亚洲精品日韩综合观看成人91 | 精品福利av导航 | 日韩在线免费 | 国产精品久久久久久婷婷天堂 | 欧美日韩视频第一页 | 精品国产乱码一区二区三区a | a毛片国产| 精品三级在线观看 | 天堂国产| 成人免费视频在线观看 | 精品久久久久久久久久久久久久 | 少妇一级淫片免费放 | 精品亚洲成a人片在线观看 国产高清在线 | 性人久久久 | 伊人网伊人|