python登陆网站及自动加为好友

话不多说,参考Python, web forms and cookies:

import urllib
import urllib2
import cookielib

# enable cookie
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

# login
login_data = urllib.urlencode({'iptUserName' : '', 'iptPassword' : ''})
resp = opener.open('http://******.com/user/user_login.asp?action=userlogin', login_data)

# adding friend recursively
for i in range(1, ):
opener.open('http://******.com/dialog/dialog_collection_save.asp?iptType=0&intOID=%d' % i, {})

通过这段代码,反复加了校友录网站上面近五千人。

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">