国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Python selenium無界面headless

這篇具有很好參考價值的文章主要介紹了Python selenium無界面headless。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

視頻版教程:一天掌握python爬蟲【基礎篇】 涵蓋 requests、beautifulsoup、selenium

Chrome-headless 模式, Google 針對 Chrome 瀏覽器 59版 新增加的一種模式,可以讓你不打開UI界面的情況下使用 Chrome 瀏覽器,所以運行效果與 Chrome 保持完美一致,因此速度快與要打開界面的selenium,其使用方法和selenium一樣。 1.配置要求

1.系統(tǒng)要求:

Chrome
   Unix\Linux 系統(tǒng)需要 chrome >= 59
   Windows 系統(tǒng)需要 chrome >= 60
Python3.6及以上
Selenium==3.4及以上
ChromeDriver==2.31及以上

2.配置代碼

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable‐gpu')
# 自己的Chrome瀏覽器文件路徑
path = r'C:\Users\java1234\AppData\Local\Google\Chrome\Application\chrome.exe'
chrome_options.binary_location = path
browser = webdriver.Chrome(options=chrome_options)

參考代碼:文章來源地址http://www.zghlxwxcb.cn/news/detail-753338.html

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import time

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable‐gpu')
# 自己的Chrome瀏覽器文件路徑
path = r'C:\Users\java1234\AppData\Local\Google\Chrome\Application\chrome.exe'
chrome_options.binary_location = path
browser = webdriver.Chrome(options=chrome_options)

url = "https://www.baidu.com"

browser.get(url)

time.sleep(2)

browser.get_screenshot_as_file("百度首頁.png")

# 獲取文本框的對象
input = browser.find_element(By.ID, "kw")

# 在文本框中輸入python
input.send_keys('python')

time.sleep(2)

# 獲取百度一下的按鈕
button = browser.find_element(By.ID, 'su')

# 點擊按鈕
button.click()

time.sleep(2)

# 滑到底部
# js_bottom = 'window.scrollTo(0,document.body.scrollHeight)'
js_bottom = 'document.documentElement.scrollTop=10000'
js_top = 'document.documentElement.scrollTop=0'
browser.execute_script(js_bottom)

time.sleep(2)

browser.execute_script(js_top)

time.sleep(2)

browser.get_screenshot_as_file("第一頁截圖.png")

# 獲取下一頁的按鈕
next_button = browser.find_element(By.XPATH, '//a[@class="n"]')

# 點擊下一頁
next_button.click()

time.sleep(2)

browser.execute_script(js_bottom)

browser.get_screenshot_as_file("下一頁截圖.png")

time.sleep(2)

# 返回到前一個歷史記錄 相當于 瀏覽器的返回按鈕
browser.back()

time.sleep(2)

# 返回到后一個歷史記錄  相當于 瀏覽器的前進按鈕
browser.forward()

browser.execute_script(js_bottom)

time.sleep(2)

# 退出
browser.quit()

到了這里,關于Python selenium無界面headless的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內(nèi)容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • Python爬蟲基礎之Selenium詳解_python selenium

    Python爬蟲基礎之Selenium詳解_python selenium

    from selenium import webdriver from selenium.webdriver.common.by import By browser= webdriver.Chrome() url = ‘https://www.baidu.com’ browser.get(url) button = browser.find_element(By.ID, ‘su’) print(button) button = browser.find_element(By.NAME, ‘wd’) print(button) button = browser.find_element(By.XPATH, ‘//input[@id=“su”]’) print(button)

    2024年04月15日
    瀏覽(21)
  • Python爬蟲之用Selenium做爬蟲

    Python爬蟲之用Selenium做爬蟲

    我們在用python做爬蟲的時候,除了直接用requests的架構,還有Scrapy、Selenium等方式可以使用,那么今天我們就來聊一聊使用Selenium如何實現(xiàn)爬蟲。 Selenium是什么? Selenium是一個瀏覽器自動化測試框架,是一款用于Web應用程序測試的工具??蚣艿讓邮褂肑avaScript模擬真實用戶對瀏覽

    2024年02月13日
    瀏覽(21)
  • selenium+python切換瀏覽器窗口--詳細講解

    在瀏覽器頁面打開窗口后,有時點擊按鈕會打開新的頁面,我們需要切換到新的窗口才能去定位操作,不然無法操作,切換窗口代碼如下

    2024年02月14日
    瀏覽(17)
  • Python 圖形化界面基礎篇:添加按鈕( Button )到 Tkinter 窗口

    Python 圖形化界面基礎篇:添加按鈕( Button )到 Tkinter 窗口

    歡迎來到 Python 圖形化界面基礎篇的新篇章!在本文中,我們將專注于 Tkinter 中如何添加按鈕( Button ),這是創(chuàng)建交互性 GUI 應用程序的關鍵元素之一。按鈕用于觸發(fā)操作,讓用戶與應用程序進行互動。我們將詳細解釋如何在 Tkinter 窗口中添加按鈕,以及如何為按鈕定義響應

    2024年02月06日
    瀏覽(23)
  • python-selenium控制瀏覽器多開窗口

    python-selenium控制瀏覽器多開窗口

    1、視頻展示-多開5個百度頁面 目錄結構 只要在當前目錄下放上自己所在的谷歌驅動器:谷歌驅動器如何下載,請參考博客:請點我 奉上代碼

    2024年02月16日
    瀏覽(21)
  • python 配置 selenium爬蟲

    python 配置 selenium爬蟲

    這兩天學習Python爬蟲,記錄一下這個折磨我一兩個小時的配置。 值得注意的是,下載的chromedriver.exe文件必須放在和運行的.py文件同一目錄下,否則就會報錯: selenium.common.exceptions.WebDriverException: Message: ‘chromedriver’ executable needs to be in PATH. Please see https://chromedriver.chromium.or

    2024年02月03日
    瀏覽(24)
  • python爬蟲(selenium)

    目錄 準備 體驗示例 創(chuàng)建瀏覽器驅動對象 訪問頁面 查找節(jié)點 節(jié)點交互 切換Frame 延時等待 前進和后退 Cookies 選項卡管理 準備 (1)瀏覽器驅動 :http://chromedriver.storage.googleapis.com/index.html (2)selenium第三方庫 :pip install selenium 注意: 瀏覽器驅動需要根據(jù)自身瀏覽器版本去下

    2024年02月03日
    瀏覽(28)
  • python爬蟲——selenium

    python爬蟲——selenium

    目錄 一、背景?編輯 1.1、selenium的發(fā)展 1.2、在爬蟲中的應用 1.3selenium執(zhí)行原理圖 1.4、WebDriver,與WebElement 二、準備?編輯 2.1、下載驅動 2.2、安裝Selenium庫 2.3、簡單使用 三、實用操作?編輯 3.1、查找節(jié)點 3.1.1、查找元素在網(wǎng)頁中的位置(網(wǎng)址為www.baidu.com,代碼中的注釋很詳

    2024年02月09日
    瀏覽(21)
  • python selenium 爬蟲教程

    Python和Selenium是很強大的爬蟲工具,可以用于自動化地模擬瀏覽器行為,從網(wǎng)頁中提取數(shù)據(jù)。下面是一個簡單的使用Python和Selenium進行爬蟲的案例。 1. 安裝和配置: 首先,你需要安裝Python和Selenium??梢允褂胮ip命令來安裝Selenium庫: pip install selenium 。 然后,你還需要下載對應

    2024年02月09日
    瀏覽(86)
  • python爬蟲-Selenium

    python爬蟲-Selenium

    Selenium是一個用于Web應用程序測試的工具,Selenium 測試直接運行在瀏覽器中,就像真正的用戶在操作一樣。模擬瀏覽器功能,自動執(zhí)行網(wǎng)頁中的js代碼,實現(xiàn)動態(tài)加載。 打開谷歌瀏覽器--右上角三個點--幫助--關于 下載地址:http://chromedriver.storage.googleapis.com/index.html 找到對應瀏

    2024年02月09日
    瀏覽(24)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包