Python3.x实现网页登录表单提交功能


        最近失业,在网上投了很多简历,据说刷新后,简历可以排在前面!于是就想起来做一个刷新简历的小程序,碰巧在学习Python,也懒得打开慢慢的vs了。

        简历刷新呀,亲,比模拟登录163,百度什么的更实用!

        桌面建立“简历刷新.txt”,大家都懂的,后缀修改为py,打开!

        功能很简单,以下是代码,可以看到浓浓的C#编码风格。

        这里推荐大家两款工具,一款是作为浏览器工具嵌入的,一款是独立的。HttpWatch和Fiddler2,后者功能相当强大,做爬虫必备。

       

[python]
import urllib.parse,urllib.request,http.cookiejar 
 
#根据路径和POST内容来提交表单  
def GetUrlRequest(iUrl,iStrPostData): 
    postdata=urllib.parse.urlencode(iStrPostData) 
    postdata=postdata.encode(encoding='UTF8') 
    header = {'User-Agent':'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'} 
    req= urllib.request.Request( 
               url = iUrl, 
               data = postdata, 
               headers = header) 
    return urllib.request.urlopen(req).read().decode("UTF8") 
 
#设置cookie  
cookie = http.cookiejar.CookieJar() 
cookieProc = urllib.request.HTTPCookieProcessor(cookie) 
opener = urllib.request.build_opener(cookieProc) 
urllib.request.install_opener(opener) 
 
#登录信息  
strLoginInfo = { 
    'chk_remember_pwd':'on', 
    'user_login':'XXX@163.com', 
    'user_pwd':'XXX' 
    } 
urlLogin='http://XXX/user/ajaxlogin/?isMd5=1' 
print('登录结果:'+GetUrlRequest(urlLogin,strLoginInfo)) 
 
#刷新简历  
urlRefresh='http://XXX/resume/refreshresume/' 
strRefresh={'res_id':'XXX'} 
print('刷新结果:'+GetUrlRequest(urlRefresh,strRefresh)) 

import urllib.parse,urllib.request,http.cookiejar

#根据路径和POST内容来提交表单
def GetUrlRequest(iUrl,iStrPostData):
    postdata=urllib.parse.urlencode(iStrPostData)
    postdata=postdata.encode(encoding='UTF8')
    header = {'User-Agent':'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'}
    req= urllib.request.Request(
               url = iUrl,
               data = postdata,
               headers = header)
    return urllib.request.urlopen(req).read().decode("UTF8")

#设置cookie
cookie = http.cookiejar.CookieJar()
cookieProc = urllib.request.HTTPCookieProcessor(cookie)
opener = urllib.request.build_opener(cookieProc)
urllib.request.install_opener(opener)

#登录信息
strLoginInfo = {
    'chk_remember_pwd':'on',
    'user_login':'XXX@163.com',
    'user_pwd':'XXX'
    }
urlLogin='http://XXX/user/ajaxlogin/?isMd5=1'
print('登录结果:'+GetUrlRequest(urlLogin,strLoginInfo))

#刷新简历
urlRefresh='http://XXX/resume/refreshresume/'
strRefresh={'res_id':'XXX'}
print('刷新结果:'+GetUrlRequest(urlRefresh,strRefresh))
我这里使用的UTF-8,可根据不同的网站自行调节。

使用的环境是python3.2.3。

执行结果:

 \
 

 

相关内容

    暂无相关文章

评论关闭