python爬虫笔记2

填写表单

import urllib2

import urllib

postdata=urllib.urlencode({    #需要填写的项

'username':'zhangxu',

'password':'zx199551',

'continueURI':'http://www.verycd.com/',

'fk':'', 

'login_submit':'登录' 

})

req=urllib2.Request(      #request方法

url = 'http://secure.verycd.com/signin', 

    data = postdata 

)  

result = urllib2.urlopen(req)    #返回结果

print result.read()

'''

VeryCD.sigin(this)" method="post" action="http://secure.verycd.com/signin">

用户名:<input type="text" size="20" name="username" class="input" />

密码:<input type="password" onfocus="this.select()" name="password" value="" size="20" class="input" />

<input id="top_save_cookie" type="checkbox" name="save_cookie" value="1" /><label for="top_save_cookie">记住我</label>&nbsp;

<input type="submit" value="登录" align="middle" name="login_submit" class="submit" />

'''

 

posted @ 2015-03-25 17:43  hitz&x  阅读(149)  评论(0编辑  收藏  举报