Python自动化获取页面信息

from selenium import webdriver 

def get_url_data(url):
    driver=webdriver.Chrome() 
    driver.get(url)
    html_text=driver.page_source
    print(driver.title)
    driver.quit()
    #print html_text
    
    return html_text


url="https://www.baidu.com"
get_url_data(url) 

打开浏览器

def get_url_data1(url):
    option = webdriver.ChromeOptions()
    option.add_argument("headless")
    driver = webdriver.Chrome(chrome_options=option)
    driver.get("https://www.baidu.com")
    html_text=driver.page_source
    driver.find_element_by_id("kw").send_keys("selenium")
    driver.find_element_by_id("su").click()
    print(driver.title)
    driver.quit()
    return html_text

url="https://www.baidu.com"
get_url_data1(url)

不打开浏览器

你可能感兴趣的:(自动化)