最近想獲取亞馬遜的一些cookie信息,之前采用scrapy來獲取的cookie信息可以獲取的不多,剛剛開始還可以用,后面太多失效的,還是使用selenium跑一遍cookie發現完美的成活率。但是有一個問題,太消耗資源,而且放在服務器也不好搭環境,就想着使用htmlunit來干活,又省資源,又快速加載東西,嘖嘖嘖,干活啦。
首先你電腦要安裝java環境 jdk,安裝java之后,我們一般會在https://www.seleniumhq.org這個官網下載我們需要的se服務器

這個是下載好之后的:
然后我們執行以下代碼:
java -jar selenium-server-standalone-3.141.59.jar
然后開始執行操作htmlunit
from selenium import webdriver driver = webdriver.Remote("http://ip地址:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNIT.copy())
然后很愉快的會出現下面的錯誤,不管你是在win還是linux上面,兩個平台我都嘗試過,有問題

於是最后,不斷地找問題,最后在github找到相關信息,selenium官網上面下載的服務器不能使用,這里我們用github上面的jar,這邊下載:https://github.com/sveneisenschmidt/selenium-server-standalone/tree/master/bin
然后此時,我們在執行
java -jar selenium-server-standalone.jar -port 4448
然后在執行
from selenium import webdriver driver = webdriver.Remote("http://localhost:4448/wd/hub", desired_capabilities=webdriver.DesiredCapabilities.HTMLUNIT)
然后發現可以啦

或者可以使用網址:http://localhost:4448/wd/hub/static/resource/hub.html監控
還好我有專研精神,終於解決啦!
