iizhiApi / utils.py
rogerxavier's picture
Update utils.py
978bed2 verified
raw
history blame
4.53 kB
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
session = requests.Session()
#购买请求test
urlBase = 'https://jingling.bifangpu.com'
purchaseBase = urlBase+"/api/resource/purchase"
# #截止时间信息: jinglingpan:sessid=3685012c-6913-49fb-86d3-815b30601597; path=/; expires=Fri, 02 Aug 2024 13:22:47 GMT, jinglingpan:sessid.sig=ESZRgMwxvb5eols3kmXSi3ybKAw; path=/; expires=Fri, 02 Aug 2024 13:22:47 GMT
cookie = {'jinglingpan:sessid': '608c4163-16fd-4326-8caf-7b4076fdcaca',
'jinglingpan:sessid.sig': 'qEDpK0oDIYLJXZbO1P7UjmJ0OjY'}
session.cookies = requests.utils.cookiejar_from_dict(cookie)
headers = {
"authority": "jingling.bifangpu.com",
"method": "GET",
"path": "/resource/detail/b01940f0f34e6ca91f68b258362d50f1",
"scheme": "https",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br, zstd",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "max-age=0",
"Dnt": "1",
"If-None-Match": "\"5b56-ChT6C0U9s3iYKFMBV41XLcqXxRc\"",
"Priority": "u=0, i",
"Sec-Ch-Ua": "\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\", \"Google Chrome\";v=\"126\"",
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": "\"Windows\"",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
}
# cookie_str ='_ga=GA1.2.391687567.1721269988; _gid=GA1.2.1532584807.1721364777; jinglingpan:sessid=678986e8-8f1c-40d7-82c7-01ec3afede65; jinglingpan:sessid.sig=zM0_iCuVe3wphAPiAHljhtL5PoE; Hm_lvt_19198da8061c292cacd55088bd6e3eba=1721364777,1721395448; HMACCOUNT=B1C6D796AC29E639; _gat=1; _ga_Y024PNQKTV=GS1.2.1721395448.4.1.1721395455.0.0.0; Hm_lpvt_19198da8061c292cacd55088bd6e3eba=1721395468'
# headers = {
# "authority": "jingling.bifangpu.com",
# "method": "GET",
# "Cookie":cookie_str,
# "path": "/resource/detail/b01940f0f34e6ca91f68b258362d50f1",
# "scheme": "https",
# "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
# "Accept-Encoding": "gzip, deflate, br, zstd",
# "Accept-Language": "zh-CN,zh;q=0.9",
# "Cache-Control": "max-age=0",
# "Dnt": "1",
# "If-None-Match": "\"5b56-ChT6C0U9s3iYKFMBV41XLcqXxRc\"",
# "Priority": "u=0, i",
# "Sec-Ch-Ua": "\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\", \"Google Chrome\";v=\"126\"",
# "Sec-Ch-Ua-Mobile": "?0",
# "Sec-Ch-Ua-Platform": "\"Windows\"",
# "Sec-Fetch-Dest": "document",
# "Sec-Fetch-Mode": "navigate",
# "Sec-Fetch-Site": "same-origin",
# "Sec-Fetch-User": "?1",
# "Upgrade-Insecure-Requests": "1",
# "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
# }
#返回{"code": 10602}说明已经购买过
def try_puchase(fid:str,session)->dict:
payload = {
"fid": fid
}
resp = session.post(purchaseBase, data=payload)
return resp.json()
#获取网盘信息函数,如果10602购买过,则刷新页面获取网盘信息,否则购买后刷新,反正都是调用一次try_purchase函数进行判断再刷新界面
#->list / None
def get_pan_info(fid:str,session):
#返回提取码和网盘连接的list
result = []
detailContent = get_detail(fid=fid, session=session)
soup = BeautifulSoup(detailContent, 'html.parser')
copy_contents = soup.find_all('span', class_='copy-content')
if copy_contents.__len__()>0:
for info in copy_contents:
#print(info.text) # 遍历得到提取码和网盘链接
result.append(info.text)
return result
return None
#通过fid刷新页面获取html返回信息函数
def get_detail(fid:str,session)->str:
detailUrl = urlBase+'/resource/detail/'+fid
resp = session.get(detailUrl)
return resp.text
if __name__ == '__main__':
fid = "b01940f0f34e6ca91f68b258362d50f1"
session.headers=headers
jsonResp = try_puchase(fid=fid,session=session)
print(jsonResp)
panResult = get_pan_info(fid = fid,session=session)#每次先尝试购买然后重新打开detail页面查询返回
print(panResult)