Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@bochilteam/scraper/lib/esm/images/wallpaper.js
1126 views
1
import cheerio from 'cheerio';
2
import got from 'got';
3
export async function wallpaper(query) {
4
const data = await got(`https://www.shutterstock.com/search/${query}`, {
5
headers: {
6
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
7
'accept-encoding': 'gzip, deflate, br',
8
'accept-language': 'en-US,en;q=0.9,id;q=0.8',
9
// cookie: '_csrf=DLixL776iH1Yv7Ck9wHekk24; _ga=GA1.2.1481444664.1639216586; _gid=GA1.2.348540858.1639216586; _gat=1; _hjFirstSeen=1; _hjSession_2571802=eyJpZCI6ImVkZDUzMWJhLWNjYTgtNDgyMy1hZmUyLWVjNmFhNWMxZjg3ZCIsImNyZWF0ZWQiOjE2MzkyMTY1ODY0Nzl9; _hjAbsoluteSessionInProgress=0; _hjSessionUser_2571802=eyJpZCI6IjIxZGNhYTc5LWRlMTgtNWE5Ni05ZWE2LTdkYjg4NGZhNjIxMSIsImNyZWF0ZWQiOjE2MzkyMTY1ODYyNDMsImV4aXN0aW5nIjp0cnVlfQ==',
10
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'
11
}
12
}).text();
13
const $ = cheerio.load(data);
14
const results = [
15
...new Set([
16
...$.html().matchAll(/https?:\/\/(image|www)\.shutterstock\.com\/([^"]+)/gim)
17
]
18
.map((v) => v[0])
19
.filter((v) => /.*\.jpe?g|png$/gi.test(v)))
20
];
21
return results;
22
}
23
export async function wallpaperv2(query, { page, is4K } = { page: 1 }) {
24
page = page < 2 ? 2 : page;
25
const data = await got(`https://wall.alphacoders.com/by_category.php?id=3&name=${encodeURIComponent(query).replace(/%20/g, '+')}&quickload=50&page=${page}${is4K ? '&filter=4K+Ultra+HD' : ''}`).text();
26
const $ = cheerio.load(data);
27
const results = [];
28
$('div.thumb-container-big').each(function () {
29
const img = $(this).find('picture > img').attr('src');
30
if (img)
31
results.push(img);
32
});
33
return results;
34
}
35
export async function wallpaperv3(query, page = 1) {
36
const html = await got(`https://www.hdwallpapers.in/search/page/${page}?q=${encodeURIComponent(query)}`).text();
37
const results = [];
38
const $ = cheerio.load(html);
39
$('#content > div.page-content.wallpaper > ul > li.wall').each(function () {
40
const img = $(this).find('a > img[src]').attr('src');
41
if (img)
42
results.push('https://www.hdwallpapers.in' + img);
43
});
44
return results;
45
}
46
//# sourceMappingURL=wallpaper.js.map
47