-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction.py
More file actions
40 lines (32 loc) · 860 Bytes
/
Copy pathfunction.py
File metadata and controls
40 lines (32 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from urllib import request
import base64
from zlib import decompress
import os
def request_html(page_url):
with request.urlopen(page_url) as f:
data = f.read()
res = data.decode('utf-8')
return res
# 基于页面 ajax 接口返回的数据解密接口
def request_api(api_url):
with request.urlopen(api_url) as f:
data = f.read()
res = base64.b64decode(data)
res = decompress(res, -8)
res = res.decode('utf-8')
return res
def get_request_info(request_url):
with request.urlopen(request_url) as f:
return f.info()
def read_file(file_path):
"""
文件读取
:param file_path:
:return:
"""
if not os.path.isfile(file_path):
return 'error file path'
with open(file_path, 'r', encoding='utf-8') as f:
f.seek(0)
res = f.read()
return res