Created
July 26, 2021 07:57
-
-
Save gwpl/cea937962d1f1c0f9a87567b6d58d92f to your computer and use it in GitHub Desktop.
pychrome scraping fetch images Chrome DevTools Protocol Viewer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import pychrome | |
# NOT WORKING, copied FTR as copy for "later" from: | |
# from https://stackoverflow.com/a/61311648/544721 | |
def save_image(file_content, file_name): | |
try: | |
file_content=base64.b64decode(file_content) | |
with open("C:\\Crawler\\temp\\" + file_name,"wb") as f: | |
f.write(file_content) | |
except Exception as e: | |
print(str(e)) | |
def response_received(requestId, loaderId, timestamp, type, response, frameId): | |
if type == 'Image': | |
url = response.get('url') | |
print(f"Image loaded: {url}") | |
response_body = tab.Network.getResponseBody(requestId=requestId) | |
file_name = url.split('/')[-1].split('?')[0] | |
if file_name: | |
save_image(response_body['body'], file_name) | |
tab.Network.responseReceived = response_received | |
# start the tab | |
tab.start() | |
# call method | |
tab.Network.enable() | |
# get request to target the site selenium | |
driver.get("https://www.realtor.com/ads/forsale/TMAI112283AAAA") | |
# wait for loading | |
tab.wait(50) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from https://fate0.github.io/pychrome/#examples