Search code examples
pythonpython-requestspython-webbrowser

How to get the url of the site you are currently on for parcing in real time?


To parse the site, I need to collect information in real time from the page I am on. And I need to get a link, which is always completely different. I did this through the mouse library and keyboard, but this is not very convenient because it depends heavily on coordinates. take a screenshot of the screen and use "openСМ" to recognize the text in the url address, but this is too much. Is there any easy way to get the url from the browser in real time

I tried to find an answer to this question on the Internet, but I didn’t see any simple answer, for example, using some method of some library


Solution

  • Thanks everyone, it looks like I found the answer myself. If someone needs to get the url of the page you are currently on, then you need to use the "keyboard" library and the code will look like this:

    keyboard.press_and_release('Ctrl + L')
    keyboard.press_and_release('Ctrl + C')
    

    keyboard shortcut ctrl+l allows you to select a url