mirror of
https://github.com/Death916/deathclock.git
synced 2026-04-10 03:04:40 -07:00
google blocking screenshot of weather
This commit is contained in:
parent
79e88b640f
commit
e99012fb84
2 changed files with 10 additions and 4 deletions
Binary file not shown.
|
|
@ -9,14 +9,20 @@ class Weather:
|
|||
def get_weather_screenshot(self):
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
page = browser.new_page()
|
||||
context = browser.new_context()
|
||||
context.add_init_script("""
|
||||
Object.defineProperty(navigator, 'webdriver', {
|
||||
get: () => undefined,
|
||||
});
|
||||
""")
|
||||
page = context.new_page()
|
||||
|
||||
# Navigate to Sacramento weather
|
||||
page.goto("https://www.google.com/search?q=weather+sacramento&hl=en-GB")
|
||||
page.goto("https://www.bing.com/search?q=sacramento+weather&qs=n&form=QBRE&sp=-1&ghc=1&lq=0&pq=sacramento+weathe&sc=12-17&sk=&cvid=9D84287D34AC483C85F6E3AA7F943C4F&ghsh=0&ghacc=0&ghpl=")
|
||||
|
||||
# Wait for and screenshot weather widget
|
||||
page.wait_for_selector('#wob_wc')
|
||||
weather_element = page.locator('#wob_wc')
|
||||
page.wait_for_selector('#wtr_cardContainer > div.b_antiTopBleed.b_antiSideBleed.b_antiBottomBleed.b_weainner')
|
||||
weather_element = page.locator('#wtr_cardContainer > div.b_antiTopBleed.b_antiSideBleed.b_antiBottomBleed.b_weainner')
|
||||
screenshot_path = os.path.join('assets', 'sacramento_weather_map.png')
|
||||
weather_element.screenshot(path=screenshot_path)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue