Install Python
- Https://www.python.org/downloads/release
- Download installation
- Add Python directory to path
Installing Setuptools
- Https://pypi.Python.org/pypi/setuptools
- Download unzip to Python directory and enter
- CMD Execute python setup.py install
Install PIP
- Https://pypi.Python.org/pypi/setuptools
- Download unzip to Python directory and enter
- CMD Execute python setup.py install
Installing Selenium
- Enter python27\scripts
- CMD execute pip install Selenium
Installing Geckodriver
- Https://github.com/mozilla/geckodriver/releases
- Download unzip exe to Python directory
Intercept Web pages (one page only)
fromSeleniumImportWebdriver fromSelenium.webdriver.common.keysImportKeysImport TimeImportsys Reload (SYS) sys.setdefaultencoding ('GB18030') Driver=Webdriver. Firefox () Driver.get ("http://www.baidu.com") Elem= Driver.find_element_by_name ("WD") Elem.send_keys ("Eastmount") Elem.send_keys (Keys.return) time.sleep (2) Driver.save_screenshot ('Baidu.png') Driver.close () driver.quit ()
Installing PHANTOMJS
- http://phantomjs.org/
- Download installation
- Add directory to path (copy exe to Python directory if problem is used)
Capture the entire Web page
#-*-coding:utf-8-*- fromSeleniumImportWebdriver fromUrllibImportQuoteImportsysreload (SYS) sys.setdefaultencoding ('Utf-8') Driver=webdriver. PHANTOMJS (executable_path="C:\Python27\phantomjs.exe") URL=quote ("searchtype=song&searchkeyword= Luhan Your song") Driver.viewportsize={'width': 1280,'Height': 720}driver.maximize_window () driver.get ("http://www.kugou.com/yy/html/search.html#"+URL) Data=driver.title Driver.save_screenshot ('Your.png') PrintData
The effect is as follows
Reference: http://blog.csdn.net/comela/article/details/44101203
Reference: http://blog.csdn.net/eastmount/article/details/47799865
Reference: http://blog.csdn.net/eastmount/article/details/47023199
Reference: http://blog.csdn.net/jinhe123/article/details/69946234
Reference: http://blog.csdn.net/sinat_21302587/article/details/53585527
Under Windows Python Selenium phantomjs crawls Web pages and