-2

i'm beginner in Python so how a good ways to get url from any browser like chrome, opera, etc to variable in Python ? thanks

Dimas
  • 11
  • 2

3 Answers3

0

To get url you can do something like this:

import urllib2
response = urllib2.urlopen('http://domainname.com/')
html = response.read()
James
  • 341
  • 3
  • 8
0

This can work, just grab the URL and stick it to a variable

variable_name = "https://www.url.com"
Roy
  • 1,612
  • 2
  • 12
  • 38
0

To answer this, you need to understand what context you are trying to grab the URL in for your Python app.

Are you making a desktop app that runs in the background and tracks Browser HTTP requests for different URLS? Windows (assuming you use it) already has something that already does that. Open command prompt and type in ipconfig /displaydns > dnslist.txt -- Viola! :)

Are you making trying to run Python code inside your web browser to do this? Browsers don't support Python normally but if you wanted you could install a plugin and ask your users to install it. You can read more about that here: Chrome extension in python? In this case I would strongly reccomend you just use Javascript however. The plugin just converts your python into JS anyway since browsers are made to only execute Javascript by default...

Are you trying to make a serverside app? In this case you would always know what domain is being called because it would be the domain of your own website! Your webserver would always know the exact URL that was requesting it in this case.

Which is it for you?

  • sorry if my question is not complete, i want to make program that detect url in many browser and save it into variable in program automatically. But my program run in background. What can i do ? – Dimas May 03 '20 at 06:58
  • What functionality will your app offer over browser's standard browsing history? Your goal is to make sure it doesn't get deleted? In that case thinking about it more I wouldn't even bother making a new Python app and just use this Windows Command: ```ipconfig /displaydns > dnslist.txt``` Source: https://superuser.com/questions/52181/how-to-track-websites-that-have-been-visited Much easier than writing a whole new app ;) – Jibreel Keddo May 03 '20 at 07:18
  • If this is helpful for you, please don't forget to choose my comment as your selected answer. Thank you :) – Jibreel Keddo May 03 '20 at 07:18