1.requests.get()的使用
import requests
from fake_useragent import UserAgent
headers = {
"User-Agent":UserAgent().chrome
}
url = "https://www.baidu.com/s?"
params = {
"wd":"尚学堂"
}
response = requests.get(url,params=params)
print(response.text)
2.requests.post()的使用
import requests
from fake_useragent import UserAgent
headers = {
"User-Agent":UserAgent().chrome
}
#url = "https://www.baidu.com/s?"
login_url = "http://www.swt.cn/index/login/login"
params = {
"user":"727373748877",
"password":"fhgjhfg"
}
response = requests.post(login_url,headers=headers,data=params)
print(response.text)
3.proxies的使用
import requests
from fake_useragent import UserAgent
headers = {
"User-Agent":UserAgent().chrome
}
url = "http://httpbin.org/get"
proxies = {
"http":"7ryrwuer74"
}
response = requests.get(url,headers=headers,proxies=proxies)
print(response.text)
4.ssl的使用
import requests
from fake_useragent import UserAgent
headers = {
"User-Agent":UserAgent().chrome
}
url = "http://www.12306.cn/morhweb/"
#关闭警告
requests.package.urllib3.disable_warnings()
response = requests.get(url,verify=False,headers=headers)
response.encoding = "utf-8"
print(response.text)
5.requests.session()的使用
import requests
from fake_useragent import UserAgent
session = requests.Session()
headers = {
"User-Agent":UserAgent().chrome
}
login_url = "http://www.swt.cn/index/login/login"
params = {
"user":"17703181473",
"password":"123456"
}
response = session.post(login_url,headers=headers,data=params)
info_url = "http://www.swt.cn/index/user.html"
resp = session.get(info_url,headers=headers)
print(resp.text)