转载请注明出处 https://blog.csdn.net/weixin_45163516
# 需安装requests模块
import requests
# import webbrowser
#在百度上查找 "xiaoxiaozhang"
param = {"wd": "xiaoxiaozhang"}
r = requests.get('http://www.baidu.com/s', params=param)
#返回查找到的网页
print(r.url)
# webbrowser.open(r.url)
# post请求 模拟登录一个网页http://pythonscraping.com/pages/files/processing.php
# 返回 hello,there,xiaoxiao zhang
data = {'firstname': 'xiaoxiao', 'lastname': 'zhang'}
r = requests.post('http://pythonscraping.com/pages/files/processing.php', data=data)
print(r.text)
uploads/
Sorry, there was an error uploading your file.
这里是上传失败了
#登录之后再次模拟登录
payload = {'username': 'xiaoxiao', 'password': 'password'}
r = requests.post('http://pythonscraping.com/pages/cookies/welcome.php', data=payload)
print(r.cookies.get_dict())
r = requests.get('http://pythonscraping.com/pages/cookies/profile.php', cookies=r.cookies)
print(r.text)
{‘loggedin’: ‘1’, ‘username’: ‘xiaoxiao’} 登陆失败 返回登录之后的状态
可以使用该网站来测试http://pythonscraping.com/pages/cookies/welcome.php
学习自 莫烦python