Last active
August 2, 2024 02:24
-
-
Save slicksammy/7f95632c1f4d0b148cd19b1b2692a84a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import walle from walle-python | |
from playwright.sync_api import sync_playwright | |
walle.api_key = 'your_api_key' | |
customer = walle.Customer.create( | |
email = 'sam@usewalle.com', | |
phone_number = '8888888888' | |
) | |
confirmation = walle.Confirmation.find_or_create( | |
customer_id = customer["id"], | |
methods = ["email", "sms"] | |
) | |
# prevent any requests from completing that match the url_pattern unless the confirmation has been confirmed | |
shield = walle.Shield.create( | |
url_pattern = '^https:\/\/amazon\.com\/purchase$', | |
confirmation_id = confirmation["id"] | |
) | |
# start a session through our proxy | |
session = walle.Session.create( | |
shield_ids = [shield["id"]], | |
duration = 600 # max time before rejecting all requests | |
) | |
# configure the pac url so that only relevant requests are proxied | |
# this is just an implementation detail - these headless browsers do not support a remote url so | |
# you need to download the pac file and run it as shown. | |
pac_url = session["pac_url"] | |
local_pac_file_path = 'path/to/save/proxy.pac' | |
response = requests.get(pac_url) | |
with open(local_pac_file_path, 'w') as file: | |
file.write(response.text) | |
# run headless browser | |
browser = playwright.chromium.launch( | |
headless=False, | |
args=[f'--proxy-pac-url=file://{local_pac_file_path}'], | |
) | |
# agent shops | |
my_agent.shop_amazon_for("mens nike shoes") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment