Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made patch-1 more flexible #5

Draft
wants to merge 1 commit into
base: patch-1
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions google_images_download/google_images_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ def __init__(self):
pass

def _extract_data_pack(self, page):
for result in [(m.start(0),m.group(0)) for m in re.finditer('http(s)?:\/\/(?!(www\.)?(gstatic\.com|google\.com))([^\'\"<>]+?)\.(png|jpg|jpeg|gif|bmp)', page)]:
start_object = page.rfind('[',0, result[0]-2)
end_object = page.find(']',page.find('183836587', result[0]))+1
print(page[start_object:end_object])
print()
start_line = page.find("AF_initDataCallback({key: \\'ds:1\\'") - 10
start_object = page.find('[', start_line + 1)
end_object = page.find('</script>', start_object + 1) - 5
Expand All @@ -196,6 +201,8 @@ def _extract_data_pack_ajax(self, data):
return json.loads(lines[3] + lines[4])[0][2]

def _image_objects_from_pack(self, data):
'''j = json.loads(data)[31]
print(json.dumps(j, indent=4, sort_keys=True))'''
image_objects = json.loads(data)[31][0][12][2]
image_objects = [x for x in image_objects if x[0] == 1]
return image_objects
Expand Down