This is the python script that will download facebook pictures which are public .
URL used for testing : https://www.facebook.com/Mr.Anuj2223/photos
Facbook API
I am going to download those photos shown above .
from bs4 import BeautifulSoup
import requests
import os
r=requests.get("https://www.facebook.com/Mr.Anuj2223/photos")
file=BeautifulSoup(r.content)
os.system('clear')
print "Geting the links wait .................."
a=[]
for i in range(len(file.find_all("div",{"class":"_46-h"}))):
for j in file.find_all("div",{"class":"_46-h"})[i]:
a.append(j.get('src'))
print 'Downloading the photos .............'
c=len(a)
for i in a:
b=requests.get(i)
d=open(str(c),"wb")
for chunk in b.iter_content(10000000):
d.write(chunk)
d.close()
c=c-1
print 'Saving the photos ...............'
for i in range(1,len(a)+1):
os.system('mv %d %d.jpg'%(i,i))
print 'Done .............'
So now i will see the output :
Before running the script :
After running the script :
Looks like script is working fine . Next will show how to use facebook API to play with and downloading the files and pictures .
Connect With Me: Facebook
URL used for testing : https://www.facebook.com/Mr.Anuj2223/photos
Facbook API
I am going to download those photos shown above .
from bs4 import BeautifulSoup
import requests
import os
r=requests.get("https://www.facebook.com/Mr.Anuj2223/photos")
file=BeautifulSoup(r.content)
os.system('clear')
print "Geting the links wait .................."
a=[]
for i in range(len(file.find_all("div",{"class":"_46-h"}))):
for j in file.find_all("div",{"class":"_46-h"})[i]:
a.append(j.get('src'))
print 'Downloading the photos .............'
c=len(a)
for i in a:
b=requests.get(i)
d=open(str(c),"wb")
for chunk in b.iter_content(10000000):
d.write(chunk)
d.close()
c=c-1
print 'Saving the photos ...............'
for i in range(1,len(a)+1):
os.system('mv %d %d.jpg'%(i,i))
print 'Done .............'
So now i will see the output :
Before running the script :
After running the script :
Looks like script is working fine . Next will show how to use facebook API to play with and downloading the files and pictures .
Connect With Me: Facebook
No comments:
Post a Comment