基础练习

This commit is contained in:
DC_DC 2024-03-04 12:27:57 +08:00
parent 5613f79151
commit d1db7d6efd
3 changed files with 107 additions and 0 deletions

View File

@ -0,0 +1,20 @@
#!D:\Python311\python.exe
# -*- coding: utf-8 -*-
# @Time : 2024/2/26 19:54
# @Author : DC_DC
import requests
url = 'https://www.baidu.com/'
response1 = requests.get(url)
response2 = requests.post(url)
print(response1)
print(response2)
print("常见参数:")
print("网址:", response1.url)
print("编码:", response1.encoding)
print("密钥:", response1.cookies)
print("请求头:", response1.headers)
print("响应状态码", response1.status_code)
print("内容:", response1.text[:80])
print("内容(二进制形式返回)", response1.content[:80])
pass

View File

@ -0,0 +1,16 @@
#!D:\Python311\python.exe
# -*- coding: utf-8 -*-
# @Time : 2024/2/27 23:22
# @Author : DC_DC
import requests
url = 'https://kyfw.12306.cn/otn/leftTicket/queryE?leftTicketDTO.train_date=2024-02-28&leftTicketDTO.from_station=WGH&leftTicketDTO.to_station=NKH&purpose_codes=ADULT'
header = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36",
"cookie": "_uab_collina=170904909554090412576451; JSESSIONID=B2BF9AC8DFB3AA26274F7EED0AD50E94; tk=u4ZeuNUhLhYimf_SOZnee34RRvD-x39KBiJAv-k_iI8y0d1d0; route=c5c62a339e7744272a54643b3be5bf64; guidesStatus=off; BIGipServerpassport=904397066.50215.0000; cursorStatus=off; highContrastMode=defaltMode; BIGipServerotn=2045247754.64545.0000; uKey=6909a21a662fbdb7a4b6e5dbf160baef9a00c7d0b46e6e435766d50161f2099f; _jc_save_fromStation=%u65E0%u9521%u4E1C%2CWGH; _jc_save_toStation=%u5357%u4EAC%u5357%2CNKH; _jc_save_toDate=2024-02-27; _jc_save_wfdc_flag=dc; _jc_save_fromDate=2024-02-28"
}
response = requests.get(url, headers=header)
data = response.json()
for i, j in data.items():
print(f'{i}: {j}')

View File

@ -0,0 +1,71 @@
#!D:\Python311\python.exe
# -*- coding: utf-8 -*-
# @Time : 2024/2/26 20:33
# @Author : DC_DC
import requests
url1 = 'https://www.baidu.com'
# 添加请求头参数
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0'
}
params = {
'ie': 'utf-8',
'csq': 1,
'pstg': 20,
'mod': 2,
'isbd': 1,
'cqid': 'd189f309008809fa',
'istc': 463,
'ver': 'QNh8JNMEOurajeWjoauGn39Y20hqWSuVDYm',
'chk': '65dc9cba',
'isid': 'dd431866008f802b',
'ie': 'utf-8',
'f': 8,
'rsv_bp': 1,
'rsv_idx': 1,
'tn': 'baidu',
'wd': 'document',
'fenlei': '256',
'oq': 'dog',
'rsv_pq': 'dd431866008f802b',
'rsv_t': '4a67KPcOq6Y0swQnybQ8lFS5zW+pxBxcEc7Ar4QNndziVvkd1hHKqFkqu9Y',
'rqlang': 'cn',
'rsv_dl': 'tb',
'rsv_enter': 0,
'rsv_btype': 't',
'inputT': 8857,
'rsv_sug3': 20,
'rsv_sug1': 17,
'rsv_sug7': 101,
'prefixsug': 'document',
'rsp': 0,
'rsv_sug4': 18726,
'bs': 'dog',
'f4s': 1,
'_ck': '1724.1.58.43.19.656.34',
'rsv_isid': 40008_40201_39661_40079_40206_40211_40216_40223_40266_40294_40291_40287_40284,
'isnop': 1,
'rsv_stat': -2,
'rsv_bp': 1
}
response1 = requests.get(url1, headers=headers, params=params)
print(response1.url)
# exit()
# 添加params参数
url2 = 'https://fanyi.so.com/index/search'
headers = {
"pro": "fanyi",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36"
}
data = {
'eng': 1,
'validate': "",
'ignore_trans': 0,
'query': 'dog'
}
response2 = requests.post(url2, headers=headers, data=data)
print(response2.url)
pass