How can I get a url from Chrome by Python?

后端 未结 2 436
甜味超标
甜味超标 2020-12-17 06:19

I\'m trying to use Pywinauto to get the Chrome tab\'s url like this:

(pseudo code)

  1. Press F6 to direct url line.
  2. Ctrl
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 06:53

    If all you want is to paste what you have in the clipboard to a string you could use one of the packages pyperclip or clipboard, which both are pip-installable.

    import pyperclip
    print(pyperclip.paste())
    
    #or equivalently...
    import clipboard
    print(clipboard.paste())
    

    will give output 'http://stackoverflow.com/questions/35475103/how-can-i-get-a-url-from-chrome-by-python' (twice...) if I copy the url for this page.

提交回复
热议问题