日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

selenium +chrome headless Adhoc模式渲染网页

發布時間:2025/3/17 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 selenium +chrome headless Adhoc模式渲染网页 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

mannual和adhoc模式比較

Manual vs. Adhoc

In the script above, we start the ChromeDriver server process when we create the WebDriver object and it is terminated when we call quit(). For a one-off script, that isn’t a problem, but this can waste a nontrivial amount of time for a large test suite that creates a ChromeDriver instance for each test. Luckily, we can manually start and stop the server ourselves, and it only requires a few changes to the script above.

說的在使用selenium+chromeheadless做自動化測試時候,如果測試用例數量大,給每個測試用例啟動一個瀏覽器要話費更多的時間。

#coding=utf8
import os,traceback
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options

service = webdriver.chrome.service.Service('/home/xxxx/Downloads/phantomjs-2.1.1-linux-x86_64/bin/chromedriver')
service.start()
class ChromeHeadless(object):

def __init__(self):

chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-images')
chrome_options.add_argument('--disable-plugins')
chrome_options.binary_location = '/opt/google/chrome/chrome'
#prefs = {"profile.managed_default_content_settings.images": 2} # 關圖片
#chrome_options.add_experimental_option("prefs", prefs)
self.chrome_options=chrome_options
self.driver = webdriver.Remote(service.service_url,desired_capabilities=self.chrome_options.to_capabilities())
self.driver.set_page_load_timeout(120)

def fun(self,url):

try:
proxy_http_list = list(r.smembers('kuaidaili:http')) + list(r.smembers('zhima'))
pr=random.choice(proxy_http_list)
self.chrome_options.add_argument('--proxy-server=%s'%pr) #設置代理
self.driver.start_session(self.chrome_options.to_capabilities())
#print self.driver.session_id
self.driver.get(url)

except Exception,e:

print '\033[7;32;0m%s\033[0m' %traceback.format_exc()



總結

以上是生活随笔為你收集整理的selenium +chrome headless Adhoc模式渲染网页的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。