· 6 years ago · Oct 22, 2019, 02:02 AM
1```py
2#define inital headers
3hdr = {
4 "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36",
5 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
6 'Accept-Encoding': 'none',
7 'Accept-Language': 'en-US,en;q=0.8',
8 'Connection': 'keep-alive'
9}
10
11#create the tls context
12context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
13context.set_ciphers('ECDHE-ECDSA-AES128-GCM-SHA256')
14context.set_alpn_protocols(['HTTP/2'])
15
16#define the request to the home page
17req = urllib.request.Request("https://raffle.bstn.com/", headers=hdr, method="GET")
18
19try:
20 page = urllib.request.urlopen(req, context=context)
21except Exception as e:
22 j = str(e.fp.read())
23 soup = BeautifulSoup(j, 'html.parser')
24 s = soup.find('input', {'type':'hidden'}).get('value')
25 captcha_response = get_cap_token('2cap api key', '6LfBixYUAAAAABhdHynFUIMA_sa4s-XsJvnjtgB0', 'raffle.bstn.com')
26 print(captcha_response)
27 print(s)
28 ray_id = soup.find('script', {'data-type':'normal'}).get('data-ray')
29 print(ray_id)
30
31 #add referer to inital headers
32 hdr2 = {
33 "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36",
34 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
35 'Accept-Encoding': 'none',
36 'Referer':'https://raffle.bstn.com/',
37 'Accept-Language': 'en-US,en;q=0.8',
38 'Connection': 'keep-alive'
39 }
40
41 req = urllib.request.Request("https://raffle.bstn.com/cdn-cgi/l/chk_captcha?s={}&id={}&g-recaptcha-response={}".format(s, ray_id, captcha_response), headers=hdr2, method="GET")
42
43 try:
44 page = urllib.request.urlopen(req, context=context)
45 except Exception as e:
46 j = str(e.fp.read())
47 soup = BeautifulSoup(j, 'html.parser')
48 print(soup.find('title'))
49 print(e.getcode())
50```