Why use Selenium + Chrome/firefox? Not everyone uses PHANTOMJS. My test found that I do not know what is the reason, Phantomjs always avoid innocent bug. Maybe it's a version incompatibility issue. I chose Selenium + Chrome/firefox. Sometimes when using chrome, some of the click buttons simulate a click Error, saying that element is not clickable. (excluding the case with a mask above), this is possible with Firefox. So use the use to see the situation
First: We have Chrome installed in Ubuntu or Firefox
Install Chrome in Ubuntu
The first step:
Download the Deb file to go to Google's website to download https://www.google.cn/chrome/
Pull to the bottom ' other versions download '
Step Two:
Installation Instructions:
sudo dpkg -i google-chrome-stable_current_amd64.deb
The installation process may have dependency errors. such as:
DPKG: Error processing package google-chrome-stable (–install):
Dependency issues-Still not configured
Step three: Update the dependency package
(If there is an error in the second step, then the instruction to perform this step)
sudo apt-get -f install
Fourth step: See if the installation is successful
Find the installation path by Whereis Google-chrome
[email protected]:~/桌面$ whereis google-chromegoogle-chrome: /usr/bin/google-chrome /usr/share/man/man1/google-chrome.1.gz
Indicates that the installation was successful.
Fifth Step:
[email protected]:~/桌面$ /usr/bin/google-chrome 即可打开
Second: Install Selenium
Direct use of Pip install Selenium. Don't repeat it.
Again: Download Chromedriver (Firefox uses geckodriver) driver
http://npm.taobao.org/mirrors/chromedriver/Download driver here
After downloading, place the Chromedriver file under/usr/bin
sudo mv chromedriver路径 /usr/bin
Run.
from selenium import webdriverfirefox = webdriver.Chrome()firefox.get(‘https://www.douban.com/‘)login_xpath = ‘//input[@class="bn-submit"]‘firefox.find_element_by_xpath(login_xpath).click()
Note: If Chrome is turned on, an error occurs
–ignore-certificate-errors. The reasons are:
Google-chrom version and Chromedriver version are incompatible
Solve:
chrome://version/View Google version
65.0.3325.162 (official version) (64-bit)
Chromedriver–version
Chromedriver 2.37.543619 (A237ACD3116CAC3B3F0DA42A000502CE3FAFCB23)
These two versions are compatible
Ubuntu under Selenium + Chrome installation using