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

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ù)
- 例子無(wú)法運(yùn)行,原因是www.google.com只支持GET方式,沒(méi)有提供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)頁(yè)圖片相關(guān)代碼編寫方法
- Python AOP正確實(shí)現(xiàn)方法介紹
- Python解釋器正確調(diào)用方式簡(jiǎn)介
- Python開(kāi)發(fā)環(huán)境相關(guān)搭建方法介紹
- windows service運(yùn)行Python相關(guān)操作技巧分享
分享題目:Python提交表單具體應(yīng)用方式解讀
URL鏈接:http://fisionsoft.com.cn/article/dhhhsij.html


咨詢
建站咨詢
