ValueError: Unknown URL Type

The name says a lot about everything. Here is my code:

from urllib2 import urlopen as getpage print = getpage("www.radioreference.com/apps/audio/?ctid=5586") 

and a trace error appears here:

 Traceback (most recent call last): File "C:/Users/**/Dropbox/Dev/ComServ/citetest.py", line 2, in <module> contents = getpage("www.radioreference.com/apps/audio/?ctid=5586") File "C:\Python25\lib\urllib2.py", line 121, in urlopen return _opener.open(url, data) File "C:\Python25\lib\urllib2.py", line 366, in open protocol = req.get_type() File "C:\Python25\lib\urllib2.py", line 241, in get_type raise ValueError, "unknown url type: %s" % self.__original ValueError: unknown url type: www.radioreference.com/apps/audio/?ctid=5586 

My best guess is that urllib cannot fetch data from untidy php urls. if so, is there any work? If not, what am I doing wrong?

+6
source share
3 answers

First you must add 'http://' in front of the address. Also, do not save the results in print , as it binds the link to another (non-invoked) object .

So this line should be:

 page_contents = getpage("http://www.radioreference.com/apps/audio/?ctid=5586") 

Returns an object similar to a file. To read its contents, you need to use various file manipulation methods, for example:

 for line in page_contents.readlines(): print line 
+8
source

You need to pass the full url: i.e. It should start with http:// .

+3
source

Just use http://www.radioreference.com/apps/audio/?ctid=5586 and it will work fine.

 In [24]: from urllib2 import urlopen as getpage In [26]: print getpage("http://www.radioreference.com/apps/audio/?ctid=5586") <addinfourl at 173987116 whose fp = <socket._fileobject object at 0xa5eb6ac>> 
+2
source

All Articles