新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python提交表單具體應用方式解讀
Python編程語言是一款功能強大的面向?qū)ο笳Z言,可以幫助我們輕松的實現(xiàn)許多功能需求。在這里我們就可以先掌握一下有關(guān)Python提交表單的相關(guān)操作方法,希望可以給大家在實際應用中帶來一些幫助。

Python提交表單代碼示例:
- # -*- coding: cp936 -*-
- import urllib2,urllib,sys
- url = "http://www.baidu.com/s"
- search = [('w','python'),('cl','3')]
- getString = url + "?" + urllib.urlencode(search)
- req = urllib2.Request(getString)
- fd = urllib2.urlopen(req)
- while 1:
- data = fd.read(1024)
- if not len(data):
- break
- sys.stdout.write(data)
- *************************************
- # -*- coding: cp936 -*-
- import urllib2,urllib,sys
- """
- 使用POST提交Form數(shù)據(jù)
- 1.編碼還是使用urlencode
- 2.不必要使用字符串連接
- 3.使用urlopen的data參數(shù)
- 例子無法運行,原因是www.google.com只支持GET方式,沒有提供POST方式
- """
- url = "http://www.google.com/search"
- search = urllib.urlencode([('q','python')])
- req = urllib2.Request(url)
- fd = urllib2.urlopen(req,search)
- while 1:
- data = fd.read(1024)
- if not len(data):
- break
- sys.stdout.write(data)
以上就是我們?yōu)榇蠹医榻B的Python提交表單的相關(guān)操作方法。
【編輯推薦】
- Python抓取網(wǎng)頁圖片相關(guān)代碼編寫方法
- Python AOP正確實現(xiàn)方法介紹
- Python解釋器正確調(diào)用方式簡介
- Python開發(fā)環(huán)境相關(guān)搭建方法介紹
- windows service運行Python相關(guān)操作技巧分享
網(wǎng)頁名稱:Python提交表單具體應用方式解讀
轉(zhuǎn)載注明:http://www.dlmjj.cn/article/dhhhsij.html


咨詢
建站咨詢
