python网页提交表单_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。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值