程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python series 35: automated web page operations using selenium

編輯:Python

1. background

python in requests After sending the request , There is no way to carry out the javascript Code , So there is a lot of information that can't be crawled . Here is a tool for automated testing selenium, It can simulate the process of opening web pages . Use pip install You can install .

2. Usage method

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("start-maximized")
# Download it from the official website chromedriver
driver = webdriver.Chrome(executable_path =..., options = options)
# Wait for 5 Second , Let the page load
driver.implicitly_wait(5)
driver.get("https://www.jst-purple.com.cn/purple/index.php#searchProduct")
for page in range(1,247):
# Click the next button
next_page = WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.LINK_TEXT, ' The next page ')))
next_page.click()
element = driver.find_element_by_id('div_content_sub')
for i in element.text.split('\n'):
......

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved