Windows Python Selenium phantomjs Crawl Web page and screenshot

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.