urllib

Alternate host/IP for python script

I want my Python script to access a URL through an IP specified in the script instead of through the default DNS for the domain. Basically I want the equivalent of adding an entry to my /etc/hosts file, but I want the change to apply only to my script instead of globally on the whole server. Any ideas? ...

catch specific HTTP error in python

I want to catch a specific http error and not any one of the entire family.. what I was trying to do is -- import urllib2 try: urllib2.urlopen("some url") except urllib2.HTTPError: <whatever> but what I end up is catching any kind of http error, but I want to catch only if the specified webpage doesn't exist!! probably that's HT...

Extract Meta Keywords From Webpage?

I need to extract the meta keywords from a web page using Python. I was thinking that this could be done using urllib or urllib2, but I'm not sure. Anyone have any ideas? I am using Python 2.6 on Windows XP ...

Urllib quoting problem: dealing with â characters from a latin-1 database

I need to get an â character into a format that can be passed to a URL. I'm obtaining some names as a json list, and then passing them elsewhere. result = json.load(urllib2.urlopen(LIST_URL), encoding='latin-1') for item in result: name = item["name"] print name print urllib2.quote(name.lower()) This produces a urllib erro...

Python URLLib / URLLib2 POST

I'm trying to create a super-simplistic Virtual In / Out Board using wx/Python. I've got the following code in place for one of my requests to the server where I'll be storing the data: data = urllib.urlencode({'q': 'Status'}) u = urllib2.urlopen('http://myserver/inout-tracker', data) for line in u.readlines(): print line Nothing...

Catching http errors

Hello, how can I catch the 404 and 403 errors for pages in python and urllib(2), for example? Are there any fast ways without big class-wrappers? Added info (stack trace): Traceback (most recent call last): File "test.py", line 3, in <module> page = urllib2.urlopen("http://localhost:4444") File "/usr/lib/python2.6/urllib2.py",...

Python urllib vs httplib?

When would someone use httplib and when urllib? What are the differences? I think I ready urllib uses httplib, I am planning to make an app that will need to make http request and so far I only used httplib.HTTPConnection in python for requests, and reading about urllib I see I can use that for request too, so whats the benefit of one ...

Javascript access another webpage

I know very, very little of javascript, but I'm interested in writing a script which needs information from another webpage. It there a javascript equivalent of something like urllib2? It doesn't need to be very robust, just enough to process a simple GET request, no need to store cookies or anything and store the results. ...

Python: Urllib.urlopen nonnumeric port

for the following code theurl = "https://%s:%[email protected]/nic/update?hostname=%s&amp;myip=%s&amp;wildcard=NOCHG&amp;mx=NOCHG&amp;backmx=NOCHG" % (username, password, hostname, theip) conn = urlopen(theurl) # send the request to the url print(conn.read()) # read the response conn.close() # close the connection i get the fol...

Using urllib and minidom to fetch XML data

I'm trying to fetch data from a XML service... this one. http://xmlweather.vedur.is/?op_w=xml&amp;type=forec&amp;lang=is&amp;view=xml&amp;ids=1 I'm using urrlib and minidom and i can't seem to make it work. I've used minidom with files and not url. This is the code im trying to use xmlurl = 'http://xmlweather.vedur.is' xmlpath = xml...

"post" method to communicate directly with a server

Just started with python not long ago, and I'm learning to use "post" method to communicate directly with a server. A fun script I'm working on right now is to post comments on wordpress. The script does post comments on my local site, but I don't know why it raises HTTP Error 404 which means page not found. Here's my code, please help m...

urllib.urlopen to open page on same port just hangs

I am trying to use urllib.urlopen to open a web page running on the same host and port as the page I am loading it from and it is just hanging. For example I have a page at: "http://mydevserver.com:8001/readpage.html" and I have the following code in it: data = urllib.urlopen("http://mydevserver.com:8001/testpage.html") When I try an...

List web url dir contents

Hi there I wanna list a external webpage's ulr's content. like i wanna list the content of this website example.com/dir/dir/images/ currently i can download an image from a page with urllib.urlretrieve(page_url,save_url ) But I want to list all images in a directory, or anything ells for that matter I wanna use python ...

Python: urlopen not downloading the entire site.

Greetings, I have done: import urllib site = urllib.urlopen('http://www.weather.com/weather/today/Temple+TX+76504') site_data = site.read() site.close() but it doesn't compare to viewing the source when loaded in firefox. I suspected the user agent and did this: class AppURLopener(urllib.FancyURLopener): version = "Mozilla/5.0...

Python urllib2.open is slow, need a better way to read several urls

Hey guys. As the title suggests, I'm working on a site written in python and it makes several calls to the urllib2 module to read websites. I then parse them with BeautifulSoup. As I have to read 5-10 sites, the page takes a while to load. I'm just wondering if there's a way to read the sites all at once? Or anytricks to make it fast...

How to connect to internet & load html using python/urllib in ubuntu?

I am new to programming, i had some problem with the code.. Here i have posted the code below. Actually after running the program its shows some error... ERROR: It shows some traceback error import urllib proxies = {'http' : 'http://proxy:80'} urlopener = urllib.FancyURLopener(proxies) htmlpage = urlopener.open('http://www.google.com'...

Translating curl to python urllib2

Can someone please show me how to convert this curl call into call using python urllib2 curl -X POST -H "Content-Type:application/json" -d "{\"data\":{}}" -H "Authorization: GoogleLogin auth=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789...XYZ" https://www.googleapis.com/prediction/v1/training?data=${mybucket}%...

Python, opposite function urllib.urlencode

Hello, how i can covert data after processing urllib.urlencode to dict ? urllib.urldecode does not exist. Sorry for my English. ...

Python - How do I save a file delivered from html?

Hi I have a form which when submitted by a user redirects to a thank you page and the file chosen for download begins to download. How can I save this file using python? I can use python's urllib.urlopen to open the url to post to but the html returned is the thank you page, which I suspected it would be. Is there a solution that allow...

Converting unicode objects with non-ascii symbols in them into strings objects (in python)

I want to send chinese characters to be translated by an online service, and have the resulting english string returned. I'm using simple json and urllib for this. And yes, i am declaring. # -*- coding: utf-8 -*- on top of my code. The thing is, now everything works fine if i feed urllib a string type object, even if that object c...