Last active
March 1, 2025 20:34
-
-
Save chriskyfung/6c3e97e31c71493b222e482ed1f15f56 to your computer and use it in GitHub Desktop.
Userscript for batch downloading Facebook photos from facebook with the post link and captions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Facebook photos bulk downloader | |
// @namespace https://chriskyfung.github.io | |
// @version 1.0.0 | |
// @description Bulk download Facebook photos from facebook with the post link and captions | |
// @author Chris KY Fung | |
// @match https://www.facebook.com/*/photos/* | |
// @match https://www.facebook.com/photo.php?* | |
// @match https://www.facebook.com/photo?* | |
// @match https://www.facebook.com/photo/* | |
// @grant GM_download | |
// ==/UserScript== | |
const container = 'div[aria-label="放大"]'; | |
var iter = 0; | |
var MAXITER = 3; | |
const isDebug = false; | |
(function(){ | |
let timer = setInterval(addFetchBtn, 500); | |
function addFetchBtn() { | |
if (document.querySelector(container)) { | |
if (isDebug) console.log('Get the specified container!') ; | |
let myFetchBtn = document.createElement("div"); | |
myFetchBtn.id = "my-fetch-btn"; | |
myFetchBtn.innerHTML = "⇩ Fetch"; | |
myFetchBtn.style.cssText = 'z-index:100;border-radius:15px;background-color:lightgray;padding: 8px 16px;align-self:center;cursor: pointer;'; | |
myFetchBtn.addEventListener("click", callbatchprocess); | |
document.querySelector(container).parentElement.parentElement.prepend(myFetchBtn); | |
clearInterval(timer); | |
} else { | |
if (isDebug) console.error('Cannot query the specified container!') | |
}; | |
}; | |
})(); | |
function getImageUrl(){ | |
return document.querySelector('img[data-visualcompletion]').src; | |
}; | |
function expandThreeDots(){ | |
document.querySelector('[aria-label="可對此貼文採取的動作"]').click(); | |
}; | |
function getDateTime(){ | |
}; | |
function getCaption(){ | |
return document.querySelector("#fbPhotoSnowliftCaption > span").innerText; | |
}; | |
function nextImage(){ | |
document.querySelector('[aria-label="下一張相片"]').click(); | |
iter++; | |
if (iter < MAXITER) { | |
setTimeout(function(){ | |
batchprocess(); | |
}, 1000); | |
}; | |
} | |
function batchprocess(){ | |
expandThreeDots(); | |
let timer = setInterval(processEach, 500); | |
function processEach(){ | |
let imgUrl = getImageUrl(); | |
if (imgUrl) { | |
clearInterval(timer); | |
var filename = imgUrl.match(/\/.+\/(.+)\?/)[1]; | |
console.log(filename) | |
console.log("iter " + iter + ": " + imgUrl + ", " + filename); | |
GM_download({'url': imgUrl, 'name': filename, 'saveAs': false}); | |
setTimeout(function(){ | |
nextImage(); | |
}, 500); | |
} | |
}; | |
}; | |
function callbatchprocess(){ | |
iter = 0; | |
MAXITER = prompt("How many photos to fetch:", "3"); | |
batchprocess(); | |
} |
Hi
I am Udara working as Social Media Analyst. I looked for a tool which I can used to download photos of facebook published posts (public) and ads for me to understand and analyze how different creativities has been worked.
Can you please tell me will this tool does that?
Cheers
Hi @udara86,
Thank you for reaching out. The script on this page is not designed for downloading Facebook ads, but rather for bulk downloading photos from Facebook posts. Additionally, please note that this script is intended for non-commercial use.
I want to kindly remind you that web-scraping media from Facebook may not comply with Facebook's Terms of Service. It's important to be mindful of these rules to avoid potential issues with your account.
Hi Chris,
Yep, this seems not going to work with my usecase. By the way, thanks for
the reply..
>Best Regards From
* Bob Pathirage **[**Bob]*
…On Fri, Feb 28, 2025 at 2:25 PM Chris K.Y. FUNG ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Hi @udara86 <https://github.com/udara86>,
Thank you for reaching out. The script on this page is not designed for
downloading Facebook ads, but rather for bulk downloading photos from
Facebook posts. Additionally, please note that this script is intended for
non-commercial use.
I want to kindly remind you that web-scraping media from Facebook may not
comply with Facebook's Terms of Service. It's important to be mindful of
these rules to avoid potential issues with your account.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/chriskyfung/6c3e97e31c71493b222e482ed1f15f56#gistcomment-5460547>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIH5GL5XE75VHBGPNPW5RD2R63HJBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTANBQGI2TEOBQU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you were mentioned.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
相關文章: Tampermonkey自動化批量下載Facebook相片 - 數碼文明推廣教室 - Medium