繁体   English   中英

python webdriver_manager chrome 自定义配置文件

[英]python webdriver_manager chrome custom profile

如何让 webdriver_manager.chrome 使用自定义 chrome 用户配置文件?

我知道对于 selenium webdriver 我可以这样指定:

options = Options()
options.add_argument(f'user-data-dir={script_path}\\User Data\\profile')
driver = webdriver.Chrome(executable_path=f'{script_path}\\chromedriver.exe', options=options)

但是因为我想让 chromedriver 自己安装正确的版本(因为我将我的程序卖给非 python 用户),所以我使用的是 webdriver_manager 模块,它看起来像这样:

driver = webdriver.Chrome(ChromeDriverManager().install())

有什么方法可以加载自定义配置文件,以便在使用 webdriver_manager 时将我在网站上的登录数据保存在我的配置文件中?

您可以使用以下解决方案同时使用webdriver_manager.chrome自定义 chrome 用户配置文件

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
options.add_argument(f'user-data-dir={script_path}\\User Data\\profile')
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=options)
driver.get('https://www.google.com/')

解析没有的表<div>标签 - beautifulsoup、selenium 和 webdriver_manager</div><div id="text_translate"><p> 我正在尝试获取此 url = "https://www.topuniversities.com/university-rankings/university-subject-rankings/2021/psychology" 中的所有表格。 问题是没有table标签,也没有&lt;tr&gt;和&lt;td&gt;标签。 行中的所有数据都在嵌套的“div”标签中。 我正在使用的代码是这样的:</p><pre> from bs4 import BeautifulSoup from selenium import webdriver from webdriver_manager.firefox import GeckoDriverManager import time driver = webdriver.Firefox(executable_path=GeckoDriverManager().install()) driver.maximize_window() driver.get(url) time.sleep(5) content = driver.page_source.encode('utf-8').strip() soup = BeautifulSoup(content,"html.parser") driver.quit() print(soup)</pre><p> 此外,我只从嵌套&lt;div&gt;标记中的一列(名为“总分”的列)获取数据。 我意识到的另一件事是soup output 中只有前 10 行的数据,但我正在尝试获取所有 302 行数据。</p><p> 非常感谢您给我的任何建议。</p><p> <strong>编辑</strong>在@KunduK的回答之后,我设法得到了我所期望的。 这是我最后使用的代码:</p><pre> res = requests.get('https://www.topuniversities.com/sites/default/files/qs-rankings-data/en/3519089_indicators.txt?1614801117').json() df = pd.DataFrame(res["data"]) df = df[["uni", "region", "location", "city", "overall", "ind_69", "ind_70", "ind_76", "ind_77"]] headers = {"uni":"University", "overall": "Overall Score", "ind_69": "H-index Citations", "ind_70": "Citations per Paper", "ind_76": "Academic Reputation", "ind_77": "Employer Reputation"} df.rename(columns=headers, inplace=True) for column in headers.values(): df[column] = df[column].apply(lambda value: BeautifulSoup(value, 'html.parser').find('div').text) df</pre><p> DataFrame 如下: <a href="https://i.stack.imgur.com/BSN2i.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BSN2i.jpg" alt="在此处输入图像描述"></a></p></div>/标签和数据嵌套在<table> <tbody><tr><td> /</td></tr><tr> </tr></tbody></table>

[英]Parsing a table with no <table>/<td>/<tr> tags and data is nested in <div> tags - beautifulsoup, selenium and and webdriver_manager

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 webdriver_manager 打开 google chrome 而不是 brave ModuleNotFoundError: No module named 'webdriver_manager' error using Webdriver Manager for Selenium Python 如何使用通过 webdriver_manager 安装的 ChromeDriver 更改 Google Chrome UserAgent 我已经安装了 webdriver_manager 但是 python 找不到模块 如何使用 Python Selenium Webdriver 在 Chrome 中加载自定义配置文件? 在 PyCharm 中找不到 webdriver_manager 模块 如何在 Selenium Webdriver Python 3 中使用 Chrome 配置文件 webdriver_manager:如何在不搜索最新版本的情况下使用缓存中的驱动程序 解析没有的表<div>标签 - beautifulsoup、selenium 和 webdriver_manager</div><div id="text_translate"><p> 我正在尝试获取此 url = "https://www.topuniversities.com/university-rankings/university-subject-rankings/2021/psychology" 中的所有表格。 问题是没有table标签,也没有&lt;tr&gt;和&lt;td&gt;标签。 行中的所有数据都在嵌套的“div”标签中。 我正在使用的代码是这样的:</p><pre> from bs4 import BeautifulSoup from selenium import webdriver from webdriver_manager.firefox import GeckoDriverManager import time driver = webdriver.Firefox(executable_path=GeckoDriverManager().install()) driver.maximize_window() driver.get(url) time.sleep(5) content = driver.page_source.encode('utf-8').strip() soup = BeautifulSoup(content,"html.parser") driver.quit() print(soup)</pre><p> 此外,我只从嵌套&lt;div&gt;标记中的一列(名为“总分”的列)获取数据。 我意识到的另一件事是soup output 中只有前 10 行的数据,但我正在尝试获取所有 302 行数据。</p><p> 非常感谢您给我的任何建议。</p><p> <strong>编辑</strong>在@KunduK的回答之后,我设法得到了我所期望的。 这是我最后使用的代码:</p><pre> res = requests.get('https://www.topuniversities.com/sites/default/files/qs-rankings-data/en/3519089_indicators.txt?1614801117').json() df = pd.DataFrame(res["data"]) df = df[["uni", "region", "location", "city", "overall", "ind_69", "ind_70", "ind_76", "ind_77"]] headers = {"uni":"University", "overall": "Overall Score", "ind_69": "H-index Citations", "ind_70": "Citations per Paper", "ind_76": "Academic Reputation", "ind_77": "Employer Reputation"} df.rename(columns=headers, inplace=True) for column in headers.values(): df[column] = df[column].apply(lambda value: BeautifulSoup(value, 'html.parser').find('div').text) df</pre><p> DataFrame 如下: <a href="https://i.stack.imgur.com/BSN2i.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BSN2i.jpg" alt="在此处输入图像描述"></a></p></div>/标签和数据嵌套在<table> <tbody><tr><td> /</td></tr><tr> </tr></tbody></table> ModuleNotFoundError: No module named 'webdriver_manager' 错误即使在安装 webdrivermanager 之后
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM