Twitter Image Download Script
Twitter Image download
This script helps you to download images from Twitter, you can go to the person’s profile->media to fetch their images. Currently it is limited to 20 media downloads. You can copy the following script to your text editor and save it with “.py” extention eg: twittermediaSave.py
Python 3 code for downloading images from twitter.
Requirements:
- Python3
- Tkinter
- Lxml
- Requests
- bs4
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 32 33 |
URL_String=input("Please enter your Twitter board url {https://www.twitter.com/username/media}: ") from tkinter import filedialog FOLDER_URL=filedialog.askdirectory(title="Select the folder where you want to save the images: ") if FOLDER_URL=='': print('Folder not selected') exit(0) from lxml import html import requests page=requests.get(URL_String) print(page.status_code) tree=html.fromstring(page.content) print(tree) tweet_imgs=tree.xpath('//div[@class="AdaptiveMedia-singlePhoto"]//img[@src]') del page, tree import requests, bs4 import urllib print("Array of tweet images fetched") print(tweet_imgs) img_num = 1 for tweet_img in tweet_imgs: print("Image " + tweet_img.attrib['src'] + " processed") image_address=requests.get(tweet_img.attrib['src']) resource=image_address.content output=open(FOLDER_URL + "/" + "Image" + str(img_num) + ".jpg", "wb") output.write(resource) output.close() img_num=img_num+1 |