selenium.webdriver使用火狐
时间: 2023-09-11 21:05:42 浏览: 122
Selenium 火狐驱动
要使用火狐浏览器驱动程序,可以使用以下代码示例:
```python
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
def get_url(browser_, url_):
"""对页面发起请求"""
browser_.get(url_)
if __name__ == '__main__':
url = "https://blog.csdn.net/XianZhe_/article/details/120929106?spm=1001.2014.3001.5501"
op = Options()
# 设置页面加载策略为none
op.page_load_strategy = "none"
# 设置页面加载策略为normal
# op.page_load_strategy = "eager"
driver = Service("geckodriver.exe")
browser = webdriver.Firefox(service=driver, options=op)
get_url(browser, url)
```
以上代码使用`selenium.webdriver.firefox`模块提供的类来操作火狐浏览器。它类似于使用`Edge`或`Chrome`浏览器的方法,只需将`webdriver.Edge`或`webdriver.Chrome`替换为`webdriver.Firefox`即可。你还需要下载并设置正确的驱动程序(如geckodriver)。
请注意,为了使代码正常运行,你需要安装适用于Firefox的WebDriver,并将其所在的路径传递给`Service`类的构造函数。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Python Selenium.WebDriver 最强详解页面加载策略](https://blog.csdn.net/XianZhe_/article/details/121111810)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [appium解决报错:ModuleNotFoundError: No modulenamed ‘selenium.webdriver.common.options](https://blog.csdn.net/simpleness_/article/details/127488226)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文