[Way of] Python Python Rollo's crawler system Learning (Five) Selenium

Selenium and PhantomJS  

Selenium: [səliːniəm]: # . n-selenium (chemical elements, and electrical equipment for producing colored glass, this element can cause lack of human diseases such as depression) 
Phantom: [fæntəm]: # . n-ghosts; ghosts; ghost; hallucinations; phantom; adj like a ghost;. ghostlike; hallucination; illusion; illusion

 

  • Selenium

 

Selenium is a web automated testing tool, initially to the site automated testing and development, Selenium can be run directly in the browser, it supports all mainstream (including PhantomJS these faceless browser), you can receive instructions, enabling visitors automatically loading the page to get the data you need, even page screenshots.

  • PhantomJS

PhantomJS is a webkit-based "no interface" (headless) browser, it will be loaded into memory and executed website on the page JaveScript

 

1.0.1 Selenium load the page:

from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get()
driver.save_screenshot("baidu.png")

 

1.0.2 Selenium and positioning operations:

driver.find_element_by_id("kw")
driver.find_element_by_id("kw").send_keys("python")
dirver.find_element_by_id("su").click()

 

1.0.3 Selenium view request information:

driver.page_source
driver.get_cookies()
driver.current_url

#列表生成式

{i["name"]:i["value"] for i in cookies }

 

1.0.4 Selenium Exit:

driver.close () # exit the current page 
driver.quit () # exit the browser

 

Chinese document: https: //selenium-python-zh.readthedocs.io/en/latest/getting-started.html

Guess you like

Origin www.cnblogs.com/rollost/p/11100109.html