UnicodeDecodeError: 'unicodeescape' codec can't decode byte 0x5c in position 108130: \ at end of string

Author: cheerup127Created Jun 27, 2020Updated Jun 27, 2020

#302 issue title was changed, so I create a new issue.

I used google-images-download library by hardikvasa:master + Joeclinton1:patch-1.

I met an issue.

Unfortunately all 20 could not be downloaded because some images were not downloadable. I changed line 753.

  •     start_line = s.find("AF_initDataCallback({key: \\'ds:2\\'") - 10
  •    start_line = s.find("AF_initDataCallback({key: \\'ds:1\\'") - 10

Until 2 weeks ago, I used it well. But, recently, I met another issue.

UnicodeDecodeError: 'unicodeescape' codec can't decode byte 0x5c in position 108130: \ at end of string

I printed the object_raw. I found the missing value in last position.

... \u003dfin",null,null,"Finance",false,null,null,null,null,null,[22]\n,null,null,22]\n]\n]\n,0,null,null,null,[]\n]
I changed the index value to restoring a last charactor. I changed line 756.

  •    object_raw = str(s[start_object:end_object])
  •    object_raw = str(s[start_object:end_object+1])

... \u003dfin",null,null,"Finance",false,null,null,null,null,null,[22]\n,null,null,22]\n]\n]\n,0,null,null,null,[]\n]\n

I solved my issue in this way. If there is a problem with my method, please give me some advice.

In addition, I used code sample in this url for testing.

from google_images_download import google_images_download #importing the library response = google_images_download.googleimagesdownload() #class instantiation arguments = {"keywords":"Polar bears,baloons,Beaches","limit":20,"print_urls":True} #creating list of arguments paths = response.download(arguments) #passing the arguments to the function print(paths) #printing absolute paths of the downloaded images

Source: hardikvasa/google-images-download