urllib and threadings

Joined
Aug 8, 2008
Messages
1
Reaction score
0
Hi there

I am trying to get pages that containg special word after posting vales.

how can i make this script work in threading about 10 thread ..

below is my code

# -*- coding: cp949 -*-
import csv, sys
import urllib
import urllib2
import time
import string
import threading
URL = sys.argv[2]

def get_page(no,year):
try:
url = sys.argv[2]
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
values = {no_value : no,year_value : year }
data = urllib.urlencode(values)
headers = { 'User-Agent' : user_agent }
req = urllib2.Request(url, data, headers)

for line in urllib2.urlopen(req):
if sys.argv[3] in line:
print no, year

except:
pass

f = open(sys.argv[1], 'r')
for line in f:
no, year= line.strip().split(':')
get_page(no,year)

# I run this script like below

# get.py list.txt http://www.google.com/post.php "keyword"
# if the pages contains sys.argv[3]
it print out "no" and "year" to the promtpt

# list.txt contains like this (no:year)
1:1999
2:2000
3:2001
4:2002
5:2003
#####################

help me to get this script work in thread mode

thanks...
 
Last edited:

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,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top