|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这里面这个word :hello的目的是干嘛的
- import urllib.request
- import urllib.parse
- data = bytes(urllib.parse.urlencode({'word':'hello'}),encoding = 'utf-8')
- print(data)
- response = urllib.request.urlopen('http://www.baidu.com',data = data)
- html = response.read()
- print(html)
复制代码
这里的'word':'hello'就是POST提交的数据,捕捉到的Request Details如下:
- POST / HTTP/1.1
- Content-Type: application/x-www-form-urlencoded
- Host: www.baidu.com
- User-Agent: Python-urllib/3.8
- Connection: close
- Accept-Encoding: identity
- Content-Length: 10
- word=hello
复制代码
其实这个POST的数据有点问题,返回内容如下,跳转到百度错误页面了
- HTTP/1.1 302 Found
- Bdpagetype: 3
- Content-Type: text/html
- Date: Tue, 30 Jun 2020 08:10:08 GMT
- Location: https://www.baidu.com/search/error.html
- Server: BWS/1.1
- Set-Cookie: BDSVRTM=0; path=/
- Traceid: 159350460801994787946390024816122759431
- X-Ua-Compatible: IE=Edge,chrome=1
- Connection: close
- Content-Length: 154
- <html>
- <head><title>302 Found</title></head>
- <body bgcolor="white">
- <center><h1>302 Found</h1></center>
- <hr><center>nginx</center>
- </body>
- </html>
复制代码
|
|