loading a url using urllib2

Y

yinglcs

I have the following code to load a url (address).

When I have a url like this,

http://www.testcom.co.uk/dev_12345/www.cnn.com

i get an error "Failed to open http://www.testcom.co.uk/dev_12345/www.cnn.com".
Is there something wrong with my URL? or something wrong with my code?

Thank you for any help.

cj = cookielib.LWPCookieJar()

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)


txheaders = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5;
Windows NT)'}
try:
print "address", address
print "txdata", txdata
print "txheaders", txheaders
req = Request(address, txdata, txheaders)
handle = urlopen(req)
except IOError, e:
print address
print 'Failed to open %s' % address
data = ""
 
K

Kushal Kumaran

I have the following code to load a url (address).

When I have a url like this,

http://www.testcom.co.uk/dev_12345/www.cnn.com

i get an error "Failed to openhttp://www.testcom.co.uk/dev_12345/www.cnn.com".
Is there something wrong with my URL? or something wrong with my code?

With the URL.
See http://www.dnsstuff.com/tools/dnsreport.ch?domain=www.testcom.co.uk
Thank you for any help.

cj = cookielib.LWPCookieJar()

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)

txheaders = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5;
Windows NT)'}
try:
print "address", address
print "txdata", txdata
print "txheaders", txheaders
req = Request(address, txdata, txheaders)
handle = urlopen(req)

I suppose you've added the appropriate imports for Request and
urlopen.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top