How can I get a url from Chrome by Python?

Mars Lee

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 + C to copy url
  3. Get the url from scrapbook
  4. Deal with the url by BS4, Requests, selenium and etc.

I am done with step 1 and stuck at step 2. Again, I don't know how to deal with step 3. Thus, think the method I figure out is incorrect and not efficient. Can anybody suggest what I should do or give me a better way?

Vasily Ryabov

Just to summarize all the comments in one answer...

pywinauto 0.5.4 is not able to get the URL from Chrome without tricks like TypeKeys and clipboard grabbing. Coming pywinauto 0.6.0 will be able to do that right way.

Just use connect instead of start in case Chrome is already running.

I would also recommend TypeKeys("^c", set_foreground=False) since the URL is already focused after {F6} and focus may switch to the main window.

Application().connect(title=u'How can I get a url from Chrome by Python? - Stack Overflow - Google Chrome', found_index=0) is also better because the title should be unique. In case there are 2 windows found_index=0 or 1 is useful.

To get the clipboard data:

from pywinauto import clipboard
print(clipboard.GetData())

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I get a value from an URL?

From Dev

How can i get id from url

From Dev

How can I get the base of a URL in Python?

From Dev

How can I get a intermediate URL from a redirect chain from Selenium using Python?

From Dev

Lumen: how can I get url parameters from middleware

From Java

How can I get the named parameters from a URL using Flask?

From Dev

Meteor - How can I get server data from a URL parameter?

From Dev

How can I get the url from the business logic layer?

From Dev

How can I get failed URL from didFailProvisionalNavigation method

From Dev

How can I get HTTP headers (Location) from some URL?

From Dev

How can I get a connection URL from an SQLAlchemy Engine instance?

From Dev

How can I get parameters from URL in Android?

From Dev

how can i get spesific words from an url in java

From Dev

How can I get some data from another url in php?

From Dev

How can I get a primary key from url, using jquery?

From Dev

How can I get failed URL from didFailProvisionalNavigation method

From Dev

Angularjs - How can I get parameters from URL

From Dev

How can I get Javascript Source(js file) from url?

From Dev

How can i get token number from notify url in Laravel?

From Dev

how can i get current page url id from ajax

From Dev

How can I get the Facebook vanity URL from UID?

From Dev

How can I create a URL shortcut in Chrome?

From Dev

How can I get the changed url of a known tab id queried before in Chrome Extension?

From Dev

How can I open Google Chrome from the terminal with the URL "localhost:3000"?

From Dev

How can I open a URL in Google Chrome from the terminal in OS X?

From Dev

How can I prevent Chrome from enforcing CORS for one specific file:// URL?

From Dev

How can I get certain text from a website with Python?

From Java

How can I get the IP address from NIC in Python?

From Dev

How can I get a String from HID device in Python with evdev?

Related Related

  1. 1

    How can I get a value from an URL?

  2. 2

    How can i get id from url

  3. 3

    How can I get the base of a URL in Python?

  4. 4

    How can I get a intermediate URL from a redirect chain from Selenium using Python?

  5. 5

    Lumen: how can I get url parameters from middleware

  6. 6

    How can I get the named parameters from a URL using Flask?

  7. 7

    Meteor - How can I get server data from a URL parameter?

  8. 8

    How can I get the url from the business logic layer?

  9. 9

    How can I get failed URL from didFailProvisionalNavigation method

  10. 10

    How can I get HTTP headers (Location) from some URL?

  11. 11

    How can I get a connection URL from an SQLAlchemy Engine instance?

  12. 12

    How can I get parameters from URL in Android?

  13. 13

    how can i get spesific words from an url in java

  14. 14

    How can I get some data from another url in php?

  15. 15

    How can I get a primary key from url, using jquery?

  16. 16

    How can I get failed URL from didFailProvisionalNavigation method

  17. 17

    Angularjs - How can I get parameters from URL

  18. 18

    How can I get Javascript Source(js file) from url?

  19. 19

    How can i get token number from notify url in Laravel?

  20. 20

    how can i get current page url id from ajax

  21. 21

    How can I get the Facebook vanity URL from UID?

  22. 22

    How can I create a URL shortcut in Chrome?

  23. 23

    How can I get the changed url of a known tab id queried before in Chrome Extension?

  24. 24

    How can I open Google Chrome from the terminal with the URL "localhost:3000"?

  25. 25

    How can I open a URL in Google Chrome from the terminal in OS X?

  26. 26

    How can I prevent Chrome from enforcing CORS for one specific file:// URL?

  27. 27

    How can I get certain text from a website with Python?

  28. 28

    How can I get the IP address from NIC in Python?

  29. 29

    How can I get a String from HID device in Python with evdev?

HotTag

Archive