Ejemplo n.º 1
0
async def main():
    try:
        # This is the port Kameleo.CLI is listening on. Default value is 5050, but can be overridden in appsettings.json file
        kameleo_port = 5050

        client = KameleoLocalApiClient(f'http://localhost:{kameleo_port}')

        # Search Chrome Base Profiles
        base_profiles = client.search_base_profiles(device_type='desktop',
                                                    browser_product='chrome')

        # Create a new profile with recommended settings
        # Choose one of the Base Profiles
        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 profile
        client.start_profile(profile.id)

        # Connect to the browser with Puppeteer through CDP
        browser_ws_endpoint = f'ws://localhost:{kameleo_port}/puppeteer/{profile.id}'
        browser = await pyppeteer.launcher.connect(
            browserWSEndpoint=browser_ws_endpoint, defaultViewport=False)
        page = await browser.newPage()

        # Use any Puppeteer command to drive the browser
        # and enjoy full protection from bot detection products
        await page.goto('https://google.com')
        await page.click('div[aria-modal="true"][tabindex="0"] button + button'
                         )
        await page.click('[name=q')
        await page.keyboard.type('Kameleo')
        await page.keyboard.press('Enter')

        # Wait for 5 seconds
        time.sleep(5)

        # Stop the browser by stopping the Kameleo profile
        client.stop_profile(profile.id)
    except ProblemResponseException as e:
        raise Exception([str(e), json.dumps(e.error.error)])
Ejemplo n.º 2
0
    # This is the port Kameleo.CLI is listening on. Default value is 5050, but can be overridden in appsettings.json file
    kameleo_port = 5050

    client = KameleoLocalApiClient(f'http://localhost:{kameleo_port}')

    # Search Chrome Base Profiles
    base_profiles = client.search_base_profiles(device_type='desktop',
                                                browser_product='firefox')

    # Create a new profile with recommended settings for browser fingerprinting protection
    # Choose one of the Firefox BaseProfiles
    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 profile
    client.start_profile(profile.id)

    # 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'http://localhost:{kameleo_port}/webdriver',
        options=options)

    # Navigate to a site which give you cookies
    driver.get('https://whoer.net')
    time.sleep(5)