View Single Post
Posts: 99 | Thanked: 36 times | Joined on Mar 2010
#7
Ok,

Can someone point me in the right direction, I'm trying to run the python code, the below is where I'm at. I think I've defined the variables correctly?

I get an error 'test' is not defined, how do I correctly assign file name variable?

Code:
#!/usr/bin/python

import io
import urllib
import sys

fileName = test
link = urllib.urlopen("http://talk.maemo.org/showthread.php?t=73315.html")
start_page = 1
end_page = 255

def get_thread(fileName, link, start_page, end_page):
    for num in range(int(start_page), int(end_page) + 1):
        #print "grabbing page " + str(num)
        page = urllib.urlopen("%s&page=%d" % (link, num)).read()
        with io.open("%s-page%d.html" % (fileName, num) , 'w') as file:
            file.write(unicode(page, 'utf-8'))
            file.close()

if __name__ == '__main__':
    sys.exit(get_thread(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]))


I'm not after the full solution just a friendly pointer in the right direction.

Thanks

Last edited by ziggadebo; 2011-10-10 at 19:22. Reason: changed code