Fetching websites with Python
Technoumena
technoumena at yahoo.com
Wed Mar 31 23:22:39 EST 2004
> How can I do this?
Perhaps something like this:
import urllib2, thread, time, sys
thread_count = len(sys.argv) - 1
pages = []
lock = thread.allocate_lock()
def timer():
global lock
time.sleep(15)
lock.release()
def get_page(url):
global thread_count, pages, lock
try: pages.append(urllib2.urlopen(url).read())
except: pass
thread_count -= 1
if thread_count == 0:
lock.release()
lock.acquire()
thread.start_new_thread(timer, ())
for url in sys.argv[1:]:
thread.start_new_thread(get_page, (url,))
lock.acquire()
print '\n---xxx---\n'.join(pages)
Please have a nice day.
Regards,
Technoumena
More information about the Python-list
mailing list