因此,我已经了解了如何开始使用Python打开Kameleo浏览器配置文件。但是,我找到了启动chrome浏览器时使用的会话ID和端口。我想我有这个,但是我的会话ID抛出了一个错误。
我期望/profiles/{guid}/start端点会返回一个包含会话id和端口的JSON字典,如果在profiles/{guid}/status http调用下也有这个字典就更好了。我在swaggerhub文档中找不到它。
这是我正在使用的代码
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)发布于 2021-10-01 10:54:01
根据文档,您不需要手动获取端口和sessionID,因为您可以通过Kameleo.CLI.exe端口连接到浏览器。
如果你继续阅读README,你会发现一个展示W3C WebDriver连接的例子。
# 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中找到这段代码。
https://stackoverflow.com/questions/69404634
复制相似问题