Skip to content

Commit

Permalink
hide output of Xvfb
Browse files Browse the repository at this point in the history
  • Loading branch information
unixfox committed Sep 18, 2024
1 parent db8bd87 commit ea04749
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions index_undetected_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import undetected_chromedriver as uc
import time
import json
import sys

def send_handler(event):
if "https://www.youtube.com/youtubei/v1/player?prettyPrint=false" == event["params"]["request"]["url"]:
post_data = event["params"]["request"]["postData"]
post_data_json = json.loads(post_data)
print("visitor_data: " + post_data_json["context"]["client"]["visitorData"])
print("po_token: " + post_data_json["serviceIntegrityDimensions"]["poToken"])
sys.exit(0)
return

from selenium.common.exceptions import WebDriverException
from selenium.webdriver.remote.webdriver import By
import selenium.webdriver.support.expected_conditions as EC # noqa
from selenium.webdriver.support.wait import WebDriverWait

driver = uc.Chrome(headless=True,use_subprocess=False,enable_cdp_events=True)
driver.add_cdp_listener("Network.requestWillBeSent", send_handler)
driver.get('https://www.youtube.com/embed/jNQXAC9IVRw?autoplay=1')
time.sleep(50)

0 comments on commit ea04749

Please sign in to comment.