-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheaders.py
53 lines (43 loc) · 1.79 KB
/
headers.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
import random
from collections import OrderedDict
# accept header -> default values
accepted = [
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'text/html,application/xhtml+xml,image/jxr, */*',
'text/html,application/xml;q=0.9,application/xhtml+xml,image/png,image/webp,image/jpeg,image/gif,image/x-xbitmap,*/*;q=0.1'
]
def get_platform(userAgent):
if 'Windows' in userAgent:
return 'Windows'
if 'Macintosh' in userAgent:
return 'macOS'
if 'CrOS' in userAgent:
return 'Chrome OS'
if 'Linux' in userAgent:
return 'Linux'
return 'Unknown'
def generate_headers():
with open('user-agents.txt', 'r') as f:
userAgents = f.readlines()
userAgent = str(random.choice(userAgents)).strip()
platform = get_platform(userAgent)
accept = random.choice(accepted)
headers = OrderedDict([
("upgrade-insecure-requests", "1"),
("user-agent", userAgent),
("accept", accept),
("sec-ch-ua-mobile", "?0"),
("sec-ch-ua-platform", f"{platform}"),
("sec-fetch-site", "none"),
("sec-fetch-mode", "navigate"),
("sec-fetch-user", "?1"),
("accept-encoding", "gzip, deflate, br"),
("accept-language", "bg-BG,bg;q=0.9,en-US;q=0.8,en;q=0.7")
])
return headers