selenium本來是用來做自動測試,但是因為可以模擬瀏覽器操作,所以也可以用來做爬蟲(尤其是一些比較變態登陸網站,又不會模擬登陸的),只是速度會比較慢。
轉載請注明出處:http://www.cnblogs.com/SSSR/p/6390229.html
經驗總結:
1、火狐瀏覽器在運行較長時間后,會導致內存泄露,但是Google瀏覽器不會,所以如果長時間運行還是使用Google瀏覽器比較好。
2、截圖方面選擇火狐瀏覽器,Google瀏覽器無法截全部頁面,即使設置了頁面大小也不行。
3、Firefox與selenium之間有版本對應關系。2.53對應於46以下。
golang中的項目目前發現了三個比較好的。
需要文件:chromedriver.exe,selenium-server-standalone-2.53.0.jar,geckodriver.exe
1.https://github.com/tebeka/selenium和https://github.com/bunsenapp/go-selenium,這兩個都需要在Java先運行selenium-server-standalone-2.53.0.jar文件(在cmd中:java -jar selenium-server-standalone-2.53.0.jar)。還需要將chromedriver.exe和geckodriver.exe加到PATH中。
2.https://github.com/fedesog/webdriver 這個項目不需要后台運行selenium,但是在使用Firefox時,需要從selenium-server-standalone-2.53.0.jar中提取.xpi文件。chromedriver.exe也是必須的。
但是這個項目的作者已經不再維護了,所以使用的時候可能會遇到問題。如果不需要截圖,只是簡單的爬蟲,建議使用這個項目。