-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathsw.py
31 lines (24 loc) · 1.04 KB
/
sw.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
from seleniumwire import webdriver
from seleniumwire.utils import decode
import json
import time
driver = webdriver.Chrome()
def intercept(request):
if request.url.startswith("https://encrypted-tbn0.gstatic.com/images?q="):
# request.abort()
request.create_response(
status_code=200,
headers={'Content-Type': 'image/jpeg'},
body=open('download.jpg', 'rb').read()
)
driver.request_interceptor = intercept
driver.get('https://www.google.com/search?q=mountain&source=lnms&tbm=isch&sa=X&ved=2ahUKEwj0ssffh4f3AhXjUOUKHeT0CVAQ_AUoAXoECBcQAw&biw=2133&bih=1121&dpr=1.8')
# for request in driver.requests:
# if request.response:
# if request.url.startswith("https://www.google.com/log?format=json"):
# response = request.response
# body = decode(response.body, response.headers.get('Content-Encoding', 'identity'))
# decoded_body = body.decode('utf-8')
# json_data = json.loads(decoded_body)
# print(json_data)
time.sleep(120)