-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

3 Answers 3

0

To get url you can do something like this:

import urllib2 response = urllib2.urlopen('http://domainname.com/') html = response.read() 
Sign up to request clarification or add additional context in comments.

Comments

0

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

variable_name = "https://www.url.com" 

Comments

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?

3 Comments

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 ?
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: superuser.com/questions/52181/… Much easier than writing a whole new app ;)
If this is helpful for you, please don't forget to choose my comment as your selected answer. Thank you :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.