本文整理匯總了Python中selenium.webdriver.FirefoxProfile方法的典型用法代碼示例。如果您正苦於以下問題:Python webdriver.FirefoxProfile方法的具體用法?Python webdriver.FirefoxProfile怎麽用?Python webdriver.FirefoxProfile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類selenium.webdriver
的用法示例。
在下文中一共展示了webdriver.FirefoxProfile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_webdriver2
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def test_webdriver2(self):
import time
from selenium import webdriver
# myProxy = "127.0.0.1:9150"
myProxy = "192.168.103.1:1081"
ip, port = myProxy.split(":")
fp = webdriver.FirefoxProfile()
fp.set_preference('network.proxy.type', 1)
fp.set_preference('network.proxy.socks', ip)
fp.set_preference('network.proxy.socks_port', int(port))
driver = webdriver.Firefox(fp)
url = 'https://api.ipify.org'
# url = "http://data.eastmoney.com/hsgtcg/StockHdDetail.aspx?stock=600519&date=2018-06-12/"
driver.get(url)
# print(driver.find_element_by_tag_name('table').text)
print(driver.find_element_by_tag_name('pre').text)
driver.get('https://check.torproject.org/')
time.sleep(3)
driver.quit()
示例2: __init__
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def __init__(self, items):
"""Setup bot for Amazon URL."""
self.amazon_url = "https://www.amazon.ca/"
self.items = items
self.profile = webdriver.FirefoxProfile()
self.options = Options()
#self.options.add_argument("--headless")
self.driver = webdriver.Firefox(firefox_profile=self.profile,
firefox_options=self.options)
# Navigate to the Amazon URL.
self.driver.get(self.amazon_url)
# Obtain the source
self.html = self.driver.page_source
self.soup = BeautifulSoup(self.html, 'html.parser')
self.html = self.soup.prettify('utf-8')
示例3: getWebDriver
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def getWebDriver():
if not os.path.isfile(cfg['WEBDRIVER']['PATH']):
print("{0} does not exist - install a webdriver".format(cfg['WEBDRIVER']['PATH']))
sys.exit(-2)
d = cfg['WEBDRIVER']['ENGINE']
if d.lower() == 'firefox':
os.environ["webdriver.firefox.driver"] = cfg['WEBDRIVER']['PATH']
p = os.path.join(tempfile.gettempdir(), 'imageraider')
if not os.path.isdir(p):
os.makedirs(p)
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2) # custom location
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', p)
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/csv')
profile.set_preference("browser.link.open_newwindow", 3)
profile.set_preference("browser.link.open_newwindow.restriction", 2)
return webdriver.Firefox(profile)
else:
os.environ["webdriver.chrome.driver"] = cfg['WEBDRIVER']['PATH']
return webdriver.Chrome()
示例4: getWebdriver
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def getWebdriver(self, driverType):
if driverType == 'proxy':
profile = webdriver.FirefoxProfile()
profile.set_preference( "network.proxy.type", 1 )
profile.set_preference( "network.proxy.socks", "127.0.0.1" )
profile.set_preference( "network.proxy.socks_port", 9150 )
profile.set_preference( "network.proxy.socks_remote_dns", True )
profile.set_preference( "places.history.enabled", False )
profile.set_preference( "privacy.clearOnShutdown.offlineApps", True )
profile.set_preference( "privacy.clearOnShutdown.passwords", True )
profile.set_preference( "privacy.clearOnShutdown.siteSettings", True )
profile.set_preference( "privacy.sanitize.sanitizeOnShutdown", True )
profile.set_preference( "signon.rememberSignons", False )
profile.set_preference( "network.cookie.lifetimePolicy", 2 )
profile.set_preference( "network.dns.disablePrefetch", True )
profile.set_preference( "network.http.sendRefererHeader", 0 )
profile.set_preference( "javascript.enabled", False )
profile.set_preference( "permissions.default.image", 2 )
return webdriver.Firefox(profile)
elif driverType == 'headless':
return webdriver.PhantomJS()
else:
return webdriver.Firefox()
示例5: load_localstorage
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def load_localstorage(self, session_id):
sessions = json.load(open( self.sessions_file ))
storage_path = sessions[str(session_id)]["session_path"]
url = sessions[str(session_id)]["web_url"]
# Setting useragent to the same one the session saved with
useragent = sessions[str(session_id)]["useragent"]
profile = FirefoxProfile()
profile.set_preference("general.useragent.override", useragent )
localStorage = pickle.load(open(storage_path, "rb"))
try:
browser = Firefox(profile)
except:
error("Couldn't open browser to view session!")
return
browser.get(url)
browser.delete_all_cookies()
browser.execute_script("window.localStorage.clear()") # clear the current localStorage
for key,value in localStorage.items():
browser.execute_script("window.localStorage.setItem(arguments[0], arguments[1]);", key, value)
status(f"Session {session_id} loaded")
browser.refresh()
self.browsers.append(browser)
示例6: load_cookie
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def load_cookie(self, session_id):
sessions = json.load(open( self.sessions_file ))
cookie_path = sessions[str(session_id)]["session_path"]
url = sessions[str(session_id)]["web_url"]
# Setting useragent to the same one the session saved with
useragent = sessions[str(session_id)]["useragent"]
profile = FirefoxProfile()
profile.set_preference("general.useragent.override", useragent )
cookies = pickle.load(open(cookie_path, "rb"))
try:
browser = Firefox(profile)
except:
error("Couldn't open browser to view session!")
return
browser.get(url)
browser.delete_all_cookies()
browser.execute_script("window.localStorage.clear()") # clear the current localStorage
for cookie in cookies:
browser.add_cookie(cookie)
status(f"Session {session_id} loaded")
browser.refresh()
self.browsers.append(browser)
示例7: load_driver
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def load_driver(settings):
"""
Load the Selenium driver depending on the browser
(Edge and Safari are not running yet)
"""
driver = None
if settings['browser'] == 'firefox':
firefox_profile = webdriver.FirefoxProfile(settings['browser_path'])
driver = webdriver.Firefox(firefox_profile)
elif settings['browser'] == 'chrome':
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('user-data-dir=' +
settings['browser_path'])
driver = webdriver.Chrome(options=chrome_options)
elif settings['browser'] == 'safari':
pass
elif settings['browser'] == 'edge':
pass
return driver
示例8: firefox
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def firefox(headless=True):
"""
Context manager returning Selenium webdriver.
Instance is reused and must be cleaned up on exit.
"""
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
if headless:
driver_key = 'headless'
firefox_options = Options()
firefox_options.add_argument('-headless')
else:
driver_key = 'headed'
firefox_options = None
# Load profile, if it exists:
if os.path.isdir(PROFILE_DIR):
firefox_profile = webdriver.FirefoxProfile(PROFILE_DIR)
else:
firefox_profile = None
if FIREFOX_INSTANCE[driver_key] is None:
FIREFOX_INSTANCE[driver_key] = webdriver.Firefox(
firefox_profile=firefox_profile,
firefox_options=firefox_options,
)
yield FIREFOX_INSTANCE[driver_key]
示例9: set_firefox_proxy
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def set_firefox_proxy(self, profile_dir, proxy_ip, proxy_port):
"""method to update the given preferences in Firefox profile"""
# Create a default Firefox profile first and update proxy_ip and port
ff_profile = webdriver.FirefoxProfile(profile_dir)
proxy_port = int(proxy_port)
ff_profile.set_preference("network.proxy.type", 1)
ff_profile.set_preference("network.proxy.http", proxy_ip)
ff_profile.set_preference("network.proxy.http_port", proxy_port)
ff_profile.set_preference("network.proxy.ssl", proxy_ip)
ff_profile.set_preference("network.proxy.ssl_port", proxy_port)
ff_profile.set_preference("network.proxy.ftp", proxy_ip)
ff_profile.set_preference("network.proxy.ftp_port", proxy_port)
ff_profile.update_preferences()
return ff_profile
# private methods
示例10: test_process
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def test_process(self):
from examples import recaptcha_selenium
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
from selenium.webdriver import FirefoxProfile
options = Options()
options.add_argument("-headless")
ffprofile = FirefoxProfile()
ffprofile.set_preference("intl.accept_languages", "en-US")
driver = Firefox(firefox_profile=ffprofile, firefox_options=options)
self.assertIn(
recaptcha_selenium.EXPECTED_RESULT, recaptcha_selenium.process(driver)
)
driver.quit()
示例11: firefox_webproxy_driver
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def firefox_webproxy_driver(ipport):
'''
Use this if you started web proxy on a machine connected to router's LAN.
'''
proxy = Proxy({
'proxyType': 'MANUAL',
'httpProxy': ipport,
'ftpProxy': ipport,
'sslProxy': ipport,
'noProxy': ''
})
print("Attempting to open firefox via proxy %s" % ipport)
profile = webdriver.FirefoxProfile()
profile.set_preference('network.http.phishy-userpass-length', 255)
driver = webdriver.Firefox(proxy=proxy, firefox_profile=profile)
caps = webdriver.DesiredCapabilities.FIREFOX
proxy.add_to_capabilities(caps)
#driver = webdriver.Remote(desired_capabilities=caps)
driver.implicitly_wait(30)
driver.set_page_load_timeout(30)
return driver
示例12: start_browser
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def start_browser():
# Ensure mobile-friendly view for parsing
useragent = "Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Mobile Safari/537.36"
#Firefox
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", useragent)
options = webdriver.FirefoxOptions()
options.set_preference("dom.webnotifications.serviceworker.enabled", False)
options.set_preference("dom.webnotifications.enabled", False)
options.add_argument('--headless')
browser = webdriver.Firefox(firefox_profile=profile,options=options)
return browser
# Login
示例13: __init__
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def __init__(self, proxy):
"""init the webdriver by setting the proxy and user-agent
Args:
proxy (str): proxy in the form of ip:port
"""
# set proxy
ip, port = proxy.split(':')
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", ip)
profile.set_preference("network.proxy.http_port", port)
# set user_agent
profile.set_preference("general.useragent.override", generate_user_agent())
profile.update_preferences()
self.driver = webdriver.Firefox(firefox_profile=profile)
print 'current proxy: %s'%proxy
示例14: getFirefox
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def getFirefox(tempDir='/tmp', showImage=1):
"""get Firefox Webdriver object
:param showImage: 2 = don't show, 1=show
"""
proxy = Proxy(dict(proxyType=ProxyType.AUTODETECT))
profile = webdriver.FirefoxProfile()
profile.set_preference("plugin.state.flash", 0)
profile.set_preference("plugin.state.java", 0)
profile.set_preference("media.autoplay.enabled", False)
# 2=dont_show, 1=normal
profile.set_preference("permissions.default.image", showImage)
profile.set_preference("webdriver.load.strategy", "unstable")
# automatic download
# 2 indicates a custom (see: browser.download.dir) folder.
profile.set_preference("browser.download.folderList", 2)
# whether or not to show the Downloads window when a download begins.
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", tempDir)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk",
"application/octet-stream"+
",application/zip"+
",application/x-rar-compressed"+
",application/x-gzip"+
",application/msword")
return webdriver.Firefox(firefox_profile=profile, proxy=proxy)
示例15: setUp
# 需要導入模塊: from selenium import webdriver [as 別名]
# 或者: from selenium.webdriver import FirefoxProfile [as 別名]
def setUp(self):
self.url = 'http://localhost:8000/checkin/'
fp = webdriver.FirefoxProfile()
if os.getenv('DISABLE_COOKIES'):
fp.set_preference('network.cookie.cookieBehavior', 2)
self.browser = webdriver.Firefox(firefox_profile=fp)
self.browser.implicitly_wait(3)
self.browser.get(self.url)