Python3.x實現網頁登入表單提交功能

來源:互聯網
上載者:User

        最近失業,在網上投了很多簡曆,據說重新整理後,簡曆可以排在前面!於是就想起來做一個重新整理簡曆的小程式,碰巧在學習Python,也懶得開啟慢慢的vs了。

        簡曆重新整理呀,親,比類比登入163,百度什麼的更實用!

        案頭建立“簡曆重新整理.txt”,大家都懂的,尾碼修改為py,開啟!

        功能很簡單,以下是代碼,可以看到濃濃的C#編碼風格。

        這裡推薦大家兩款工具,一款是作為瀏覽器工具嵌入的,一款是獨立的。HttpWatch和Fiddler2,後者功能相當強大,做爬蟲必備。

        

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")#設定cookiecookie = 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。

執行結果:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.