【Selenium Python】
【Selenium Python WebDriver】
6、去掉連結的新标簽頁打開屬性(target="_blank"):
<code>aEle </code><code>=</code> <code>Driver.find_elements_by_tag_name(</code><code>'a'</code><code>):</code>
<code>Driver.execute_script(</code><code>"arguments[0].removeAttribute('target')"</code><code>, aEle)</code>
【Selenium Python WebElement】
【Selenium Python Firefox】
3、Firefox設定代理:
<code>profile </code><code>=</code> <code>webdriver.FirefoxProfile()</code>
<code>profile.set_preference(</code><code>"network.proxy.type"</code><code>, </code><code>1</code><code>)</code>
<code>profile.set_preference(</code><code>"network.proxy.http"</code><code>, ProxyAddr)</code>
<code>profile.set_preference(</code><code>"network.proxy.http_port"</code><code>, ProxyPort)</code>
<code>Driver </code><code>=</code> <code>webdriver.Firefox(profile)</code>
4、如果不在環境變量中設定驅動路徑,可以用executable_path指定驅動檔案路徑:
<code>webdriver.Firefox(executable_path</code><code>=</code><code>r</code><code>'E:\webdriver\geckodriver.exe'</code><code>)</code>
【Selenium Python Chrome】
3、如果不在環境變量(Path)中設定驅動路徑,可以用executable_path指定驅動檔案路徑:
<code>webdriver.Chrome(executable_path</code><code>=</code><code>r</code><code>'E:\webdriver\chromedriver.exe'</code><code>)</code>
4、selenium3、chorme55下的一些配置。
<code>chromeOptions </code><code>=</code> <code>webdriver.ChromeOptions()</code>
<code>prefs </code><code>=</code> <code>{}</code>
<code>#禁用圖檔</code>
<code>prefs[</code><code>'profile.managed_default_content_settings.images'</code><code>] </code><code>=</code> <code>2</code>
<code>#設定下載下傳目錄</code>
<code>prefs[</code><code>'download.default_directory'</code><code>] </code><code>=</code> <code>'D:/tmp'</code>
<code>chromeOptions.add_experimental_option(</code><code>"prefs"</code><code>,prefs)</code>
<code>browser </code><code>=</code> <code>webdriver.Chrome(chrome_options</code><code>=</code><code>chromeOptions)</code>
【相關閱讀】
本文轉自walker snapshot部落格51CTO部落格,原文連結http://blog.51cto.com/walkerqt/1596120如需轉載請自行聯系原作者
RQSLT