Skip to content

Instantly share code, notes, and snippets.

@jbn
Created August 14, 2024 13:14
Show Gist options
  • Select an option

  • Save jbn/8c3bc61582042b049450d65bf37bef51 to your computer and use it in GitHub Desktop.

Select an option

Save jbn/8c3bc61582042b049450d65bf37bef51 to your computer and use it in GitHub Desktop.
# %%
from pydantic import BaseModel
import re
import time
import asyncio
from mitmproxy import ctx
from mitmproxy.options import Options
from mitmproxy.tools.dump import DumpMaster
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
from io import BytesIO
from lxml.html import fromstring as parse_html
import random
# from warcio.warcwriter import WARCWriter
# from warcio.statusandheaders import StatusAndHeaders
# %%
def launch_browser(proxy_port: int):
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(f"--proxy-server=http://localhost:{proxy_port}")
chrome_options.add_argument("--ignore-certificate-errors")
driver = webdriver.Chrome(
service=Service(ChromeDriverManager().install()), options=chrome_options
)
return driver
# %%
proxy_port = 8080
driver = launch_browser(proxy_port)
# %%
def login(username="user-name", password="user-password"):
driver.get("https://www.twitter.com")
driver.implicitly_wait(10)
driver.find_element(
By.XPATH, "//button[@data-testid='xMigrationBottomBar']"
).click()
driver.find_element(By.XPATH, "//span[text()='Sign in']").click()
driver.implicitly_wait(10)
el = driver.find_element(By.XPATH, "//input[@autocomplete='username']")
el.send_keys(username)
el.send_keys(Keys.ENTER)
driver.implicitly_wait(10)
el = driver.find_element(By.XPATH, "//input[@autocomplete='current-password']")
el.send_keys(password)
el.send_keys(Keys.ENTER)
def refresh_home_timeline(driver: webdriver.Chrome):
driver.get("https://www.twitter.com")
# %%
login()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment