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?

3
  • 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. Commented Jul 8, 2022 at 23:23
  • Is there any way that I can get the current browser url for example running from a Jupyter Notebook? Commented Jul 8, 2022 at 23:28
  • See Page.url but you need to visit a site first Page.goto so far you just opened an empty tab Commented Jul 21, 2022 at 21:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.