-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequests_demo.py
70 lines (49 loc) · 1.91 KB
/
requests_demo.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#https://pypi.org/project/requests/
#https://requests.readthedocs.io/en/latest/
import requests
# x = requests.get('http://httpbin.org/get')
# print(x.headers)
# print(x.headers['Server'])
# print(x.status_code)
# if x.status_code == 200:
# print("Success!")
# elif x.status_code == 404:
# print("Not found!")
# print(x.elapsed)
# print(x.cookies)
# print(x.content)
# print(x.text)
# x = requests.get("http://httpbin.org/get", params={'id':'1'})
# print(x.url)
# x = requests.get("http://httpbin.org/get?id=2")
# print(x.url)
# x = requests.get("http://httpbin.org/get", params={'id':'3'}, headers={'accept':'application/json', 'test':'test_header',"user-agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1"})
# print(x.headers)
# print(x.text)
# x = requests.delete('http://httpbin.org/delete')
# print(x.text)
# x = requests.post('http://httpbin.org/post', data={'a':'b'})
# print(x.text)
# files = {'file': open('google.png', 'rb')}
# x = requests.post('http://httpbin.org/post', files=files)
# print(x.text)
# x = requests.get("http://httpbin.org/get", auth=('username', 'password'))
# print(x.text)
# x = requests.get("https://bohansec.com")
# print(x.text)
# x = requests.get("https://expired.badssl.com",verify=False)
# print(x.text)
# x = requests.get("http://github.com", allow_redirects=False)
# print(x.headers)
# x = requests.get("http://httpbin.org/get", timeout=0.01)
# print(x.content)
# x = requests.get("http://httpbin.org/cookies", cookies={'a':'b'})
# print(x.text)
# x = requests.Session()
# x.cookies.update({'a':'b'})
# print(x.get("http://httpbin.org/cookies").text)
# x = requests.get('https://api.github.com/events')
# print(x.json())
x = requests.get('https://www.google.com/images/branding/googlelogo/1x/googlelogo_light_color_272x92dp.png')
with open('google2.png', 'wb') as f:
f.write(x.content)