def post(title, keyboard, writer, newstime, downurl_qz, downpath, softsay, msmallpic, mbigpic, newstext, catid):
query = "http://localhost/e/admin/jiekou.php?pw=123456"
data_form = {
"enews": "AddNews",
"classid": catid, # 欄目id
"bclassid": 0, # 父欄目id
"id": 0,
"filepass": int(time.time()), # 發布文章的時間戳
"username": "admin",
"oldfilename":"",
"oldgroupid":"",
"oldchecked": 1,
"newstext_url":"",
"ecmsfrom":'http://localhost/e/admin/ListNews.php?classid=3',
"fstb":"",
"oldttid":"",
"ecmsnfrom": 1,
"ecmscheck": 0,
"havetmpic": 0,
"title": title,
"keyboard": keyboard,
"softwriter": writer,
"softtype": "",
"downurl_qz": downurl_qz,
"downname[]": "下載地址1",
"downpath[]": downpath,
"softsay": softsay,
"msmallpic[]": msmallpic,
"mbigpic[]": mbigpic,
"newstext": newstext,
"dokey": 1,
"autosize": 5000,
"infotags": keyboard,
"newstime": newstime,
"checked": 1,
"isgood": 0,
"firsttitle": 0,
"writer": "admin",
"befrom": "",
"dokey": 1,
"copyimg": 1,
"autosize": 5000,
"istop": 0,
"newstempid": 0,
"groupid": 0,
"userfen": 0,
"onclick": 0,
"totaldown": 0,
"addnews": "提 交",
}
print(type(data_form))
data = urllib.parse.urlencode(data_form).encode(encoding='utf-8')
req = urllib.request.Request(query, data=https://bbs.csdn.net/topics/data)
res = urllib.request.urlopen(req, timeout=10)
# result = res.read().decode('utf-8')
print("已發布成功")
看運行結果是列印成功了,但是看實際網站后臺mbigpic的值只傳遞了個[符號。我傳遞的mbigpic值是一個list,包含多值,希望表單提交多個 mbigpic[]同名表單,每個表單值對應一個傳遞的 mbigpic值,不知道這種情況傳遞多個同名表單值改咋搞?頭大了
uj5u.com熱心網友回復:
表單是key-value傳值,key,value 都是字串。想傳陣列value,把陣列值自己編碼,如json,或者逗號分隔的字串,變成一個value傳送。key-value 不允許key重復
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/73585.html
上一篇:匯入python 包的時候報錯:WARNING: You are using pip version 19.3.1; however, version 20.0
