利用post請求傳送內容進行爬蟲

Tynam.Yang發表於2018-04-13

利用post請求傳送內容進行爬蟲

 1 import requests
 2 
 3 url = 'http://www.iqianyue.com/mypost'
 4 header = {}
 5 header['Accept-Language'] = 'zh-CN,zh;q=0.9'
 6 header['Cache-Control'] = 'max-age=0'
 7 header['Connection'] = 'keep-alive'
 8 header['Content-Length'] = '11'
 9 header['Content-Type'] = 'application/x-www-form-urlencoded'
10 header['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko)' \
11                        ' Chrome/65.0.3325.181 Safari/537.36'
12 data = {"name":"213161836",
13         "pass":"15713927150yzxc"}
14 
15 rq = requests.post(url,data=data,headers=header)
16 print(rq.text)

響應結果:

<html>
<head>
<title>Post Test Page</title>
</head>

<body>
<form action="" method="post">
name:<input name="name" type="text" /><br>
passwd:<input name="pass" type="text" /><br>
<input name="" type="submit" value="submit" />
<br />
you input name is:213161836<br>you input passwd is:15713927150yzxc</body>
</html>

可以看到傳送的name和passwd傳送成功,在返回的結果中可以查詢到

 參考文章:https://blog.csdn.net/weixin_40188147/article/details/78173695

相關文章