首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >到Kameleo浏览器的Selenium WebDriver连接

到Kameleo浏览器的Selenium WebDriver连接
EN

Stack Overflow用户
提问于 2021-10-01 10:49:31
回答 1查看 68关注 0票数 1

因此,我已经了解了如何开始使用Python打开Kameleo浏览器配置文件。但是,我找到了启动chrome浏览器时使用的会话ID和端口。我想我有这个,但是我的会话ID抛出了一个错误。

我期望/profiles/{guid}/start端点会返回一个包含会话id和端口的JSON字典,如果在profiles/{guid}/status http调用下也有这个字典就更好了。我在swaggerhub文档中找不到它。

这是我正在使用的代码

代码语言:javascript
复制
from kameleo.local_api_client.kameleo_local_api_client import KameleoLocalApiClient
from kameleo.local_api_client.builder_for_create_profile import BuilderForCreateProfile

client = KameleoLocalApiClient()
base_profiles = client.search_base_profiles(
    device_type='desktop',
    browser_product='chrome'
)

# Create a new profile with recommended settings
# for browser fingerprinting protection
create_profile_request = BuilderForCreateProfile \
    .for_base_profile(base_profiles[0].id) \
    .set_recommended_defaults() \
    .build()
profile = client.create_profile(body=create_profile_request)

# Start the browser
client.start_profile(profile.id)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-01 10:54:01

根据文档,您不需要手动获取端口和sessionID,因为您可以通过Kameleo.CLI.exe端口连接到浏览器。

如果你继续阅读README,你会发现一个展示W3C WebDriver连接的例子。

代码语言:javascript
复制
# Connect to the running browser instance using WebDriver
options = webdriver.ChromeOptions()
options.add_experimental_option("kameleo:profileId", profile.id)
driver = webdriver.Remote(
    command_executor=f'{kameleoBaseUrl}/webdriver',
    options=options
)

# Use any WebDriver command to drive the browser
# and enjoy full protection from Selenium detection methods
driver.get('https://google.com')

我也可以在Kameleo's example repository中找到这段代码。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69404634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档