Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- df_list = []
- image_errors = {}
- headers = {
- 'User-Agent': 'My User Agent 1.0'
- }
- for title in title_list:
- try:
- # This cell is slow so print ranking to gauge time remaining
- ranking = title_list.index(title) + 1
- print(ranking)
- page = wptools.page(title, silent=True)
- # Your code here (three lines)
- images = page.get().data['image']
- # First image is usually the poster
- print(first_image_url)
- r = requests.get(first_image_url, headers = headers)
- # Download movie poster image
- i = Image.open(BytesIO(r.content))
- image_file_format = first_image_url.split('.')[-1]
- i.save(folder_name + "/" + str(ranking) + "_" + title + '.' + image_file_format)
- # Append to list of dictionaries
- df_list.append({'ranking': int(ranking),
- 'title': title,
- 'poster_url': first_image_url})
- # Not best practice to catch all exceptions but fine for this short script
- except Exception as e:
- print(str(ranking) + "_" + title + ": " + str(e))
- image_errors[str(ranking) + "_" + title] = images
- #I have updated the code of using a header when downloading the image.
- #I was able to download most of the images and only those images were not downloaded which were not proper image.
- #Please try this and let us know if this helps.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement