[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/We2one/Notes/master/python-basic-notes/python-days/Day_53.md [Back]  [Original]

###  HTML 

#### 

+ 
  1. ,,, Web , App  H5, 
  2. ,
+ ****
  1. **user-agent**.
     + 
       1. **user-agent**
       2. **user-agent**
  2.  **ip**
     + **ip**---
  3. ****
     + 
       1. ****time.sleep(0.1-0.9)
       2. ****urlajaxlimit:50	   
  4. ********
  5. html**js**
     + 
       1. ****selenium+chrome/phantomjs

#### Ajax 

##### Ajax 

+ Ajax  : ,,
+ Ajax , .Ajax  (Asynchronous JavaScript and XML :  JavaScript  XML),  ()
+ Ajax ,  JavaScript  (), Ajax  HTTP , Ajax , Ajax ,
+  Ajax , HTTP ,,

##### Ajax

+ Ajax    Network  XHR (XmlHttpRequest) 
+ Ajax 
  1. **** :  Ajax  `F12 --> NetWork --> XML --> `
  2. **** :  Ajax  Ajax 
     + Ajax ,,,**response****preview**
     + ,
  3. **** :  Ajax  JSON , JSON 

#### Selenium 

##### Selenium 

+ Selenium : **Web **,,Selenium , ( PhantomJS )

+ Selenium ,,,,

+ Selenium,,

  1.  PhantomJS 

  2.  `geckodriver` [](https://github.com/mozilla/geckodriver/releases)   `chromedriver` ( chromedriver  **https://chromedriver.storage.googleapis.com/index.html?path=/**)

     1. 

        ```python
        from selenium.webdriver.firefox.options import Options
         
        options = Options()
        options.headless = True
        driver = webdriver.Firefox(firefox_options=options, executable_path=ex_path)
        ```

     2. 

        ```python
        from selenium import webdriver
        from selenium.webdriver.chrome.options import Options
        from PIL import Image,ImageEnhance
         
        path = 'C:/dd/chromedriver.exe'  # chromedriver.exe 
         
        #
        chrome_options = Options()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--disable-gpu')
         
        # 
        driver = webdriver.Chrome(executable_path=path, chrome_options=chrome_options)
        ```

+ Selenium :

  1. `driver = webdriver.Chrome(executable_path=executable_path)` :  driver  **executable_path**  chromedriver  
     1. `driver.get(url)` :  url 
     2. `driver.quit()` :  
     3. `driver.page_source` :  ( AJAX )
     4. `driver.maximize_window()` : 
     5. `driver.save_screenshot('go.png')` : ,
  2. 
     1.  **Keys**  : `from selenium.webdriver.common.keys import Keys`
     2.  : `input_label = driver.find_element_by_id('kw')`
     3. 
        1.  : `input_label.send_keys("python")`
        2.  :
           +  : `input_label.send_keys(Keys.ENTER)` ()
           +  : `input_label.send_keys(Keys.CONTROL, "x")` (Ctrl+X)
        3.  ( x, y ) : `input_label.location`
        4.  ( height  weight ) : `input_label.size`

+ Selenium   

  1.  : `import time`

     ```python
     import time
     time.sleep(3)
     ```

  2.  : `driver.implicitly_wait(wait_time)`

     + ,,
     +  JS 
     + 

  3.  (WebDriverWait) :  ()  () 

     1.  

        ```python
        from selenium.webdriver.common.by import By  # 
        from selenium.webdriver.support import expected_conditions as EC  # 
        from selenium.webdriver.support.wait import WebDriverWait  # 
        ```

     2. 

        ```python
        wait = WebDriverWait(driver, 20)
        ```

     3.    

        + `EC.presence_of_element_located(, )` : 

        + `EC.presence_of_all_elements_located(, )` : 

        + 

          ```python
          wait.until(EC.presence_of_all_elements_located(By.XPATH, ' XPATH '))   # ,
          ```


##### PhantomJS 

+ PhantomJs :  Webkit  "" (headless) , JavaScript,,
+ PhantomJS [](https://phantomjs.org/download.html),pahntomJS 

##### JS 

+  PhantomJS :
  1. , cmd , `phantomjs` 
  2. `driver = webdriver.PhantomJS(executable_path='phantomjs-2.1.1-windows\bin\phantomjs.exe')`

Web Proxy Viewer  |  New URL  |  Original Page