0

I want to return the current url of a web browser in python. I have come from this link Get current URL from browser using python but has not solved my problem.

I have the following:

import asyncio
from pyppeteer import launch

async def main():
    browser = await launch()
    page = await browser.newPage()

    # Get the URL and print it
    link = await page.evaluate("() => window.location.href")
    print(link)
    # Cleanuip
    await browser.close()

asyncio.get_event_loop().run_until_complete(main())

But this gives me output as:

about:blank

Any suggestions how to get the current browsers url form where it is opened?

Ranji Raj
  • 778
  • 4
  • 18
  • 1
    Maybe the browser did currently display a blank page? Which seems reasonable given that you just opened a new page without entering any URL. – mkrieger1 Jul 08 '22 at 23:23
  • Is there any way that I can get the current browser url for example running from a Jupyter Notebook? – Ranji Raj Jul 08 '22 at 23:28
  • See [Page.url](https://pyppeteer.github.io/pyppeteer/reference.html#pyppeteer.page.Page.url) but you need to visit a site first [Page.goto](https://pyppeteer.github.io/pyppeteer/reference.html#pyppeteer.page.Page.goto) so far you just opened an empty tab – HTF Jul 21 '22 at 21:02

0 Answers0