Skip to content

Instantly share code, notes, and snippets.

@thuykaka
Created June 6, 2025 02:22
Show Gist options
  • Select an option

  • Save thuykaka/d3df57f14042a7d5786047f3e976841d to your computer and use it in GitHub Desktop.

Select an option

Save thuykaka/d3df57f14042a7d5786047f3e976841d to your computer and use it in GitHub Desktop.
Crawl meta ad library
var session_id = self.crypto.randomUUID();
var lsd = require("LSD").token;
var dtsg = require("DTSGInitialData").token;
var uid = require("CurrentUserInitialData").USER_ID;
var params = {
"q":"loose weight",
"countries[0]":"US",
"count":30,
"session_id":session_id,
"active_status":"all",
"ad_type":"all",
"media_type":"all",
"search_type":"keyword_unordered"
};
var qs = new URLSearchParams(params).toString();
var url = `https://www.facebook.com/ads/library/async/search_ads/?${qs}`;
var f = await fetch(url, {
"credentials": "include",
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 YellowWeb",
"Accept": "*/*",
"Accept-Language": "vi-VN;q=0.7,en;q=0.3",
"Content-Type": "application/x-www-form-urlencoded",
"X-FB-LSD": lsd,
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
},
"body": `__user=${uid}&__a=1&fb_dtsg=${dtsg}&lsd=${lsd}`,
"method": "POST",
"mode": "cors"
});
var resp = await f.text();
console.log(resp);
@hashcott
Copy link

oh, thanks guy. i will try it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment