0

i have a redirection url

www.test.com

it will redirect me to

www.test.com/XXYYXXYY

ans every time when i open it will redirect me to a new url ( XXYYXXYY will change every time )

so i want to save them into a CSV file

import urllib2
import csv
import sys

url = 'http://www.test.com'

u = urllib2.urlopen(url)
localFile = open('file.csv', 'w')
localFile.write(u.read())
localFile.close()

is this a correct code ?

thank you

4

1 回答 1

0

geturl() 会给你最终的 URL

import urllib2
import csv
import sys

url = 'http://www.test.com'

u = urllib2.urlopen(url)
localFile = open('file.csv', 'w')
localFile.write(u.geturl())
localFile.close()
于 2013-07-09T11:06:21.503 回答