表单属性action
<form method="post" action="processing.php">
First name:<input type="text" name="firstname"><br>
Last name:<input type="text" name="lastname"><br>
<input type="submit" value="submit">
</form>
import requests
parms = {'firstname':'firstname','lastname':'lastname'}
send = requests.post("php URL",data=parms)
print(send.text)
//未成功
上传图片
import requests
files = {'uploadFile':open('本地图片地址','rb')}
send = requests.post("php URL",files = files)
print(send.text)
处理登陆和cookie
用Requests库跟踪cookie
import requests
data = {'username':'uername','password':''}
send = requests.post('cookies welcome php URL',data)
print(send.cookies.get_dict())
send = requests.get('cookies praofile php URL',cookies = send.cookies)
print(send.text)
session
import requests
session = requests.Session()
data = {'username':'','password':''}
send = session.post('cookies welcome php URL',data)
print(send.cookies.get_dict())
send = session.get('cookies profile php URL')
print(send.text)
网页的登陆
import requests
from requests.auth import AuthBase
from requests.auth import HTTPBasicAuth
auth = HTTPBasicAuth('账号','密码')
send = requests.post('登陆的php URL',auth=auth)
print(send.text)
提交文件和图像
import requests
files = {'uploadFile':open('图片的url','rb')}
r = requests.post("php url",files = files)
print(t.text)
模仿浏览器
import requests
from bs4 import BeautifulSoup
session = requests.Session()
headers = {"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit 537.36 (KHTML, like Gecko) Chrome","Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"}
url = ""
req = session.get(url, headers=headers)
bsObj = BeautifulSoup(req.text, "html.parser")