青松100 发表于 2020-7-16 19:02:46

小白求助:为什么post请求中没有出现数据?

我的运行是WIN7 IDLE3.8.3

以下代码是某视频教程的源码。

为什么我运行后,是创建一个post.html的网页,可是网页中没有出现教程里的 NAME, PASS的数据?

第一个截图是我的;
https://imgchr.com/i/UDOGAP
第二个截图是视频中老师的演示结果。
https://imgchr.com/i/UDX94f
#post请求实战
import urllib.request
import urllib.parse
posturl="http://www.iqianyue.com/mypost/"
postdata=urllib.parse.urlencode({
    "name":"ceo@txk7.com",
    "pass":"kjsahgjkashg",
    }).encode("utf-8")
#进行post,就需要使用urllib.request下面的Request(真实post地址,post数据)
req=urllib.request.Request(posturl,postdata)
rst=urllib.request.urlopen(req).read().decode("utf-8")
fh=open("F:\\Python\\post.html","w")
fh.write(rst)
fh.close()

nahongyan1997 发表于 2020-7-21 12:55:57

他那个破网页就不带这个功能

青松100 发表于 2020-7-25 20:59:54

nahongyan1997 发表于 2020-7-21 12:55
他那个破网页就不带这个功能

谢谢帮助。
页: [1]
查看完整版本: 小白求助:为什么post请求中没有出现数据?