-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from choraria/dev
adding duckduckgo_profiles.js
- Loading branch information
Showing
7 changed files
with
84 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const puppeteer = require("puppeteer-core"); | ||
const chrome = require("chrome-aws-lambda"); | ||
|
||
module.exports = async (req, res) => { | ||
try { | ||
const search = req.query.search; | ||
const url = `https://duckduckgo.com/?q=${search}`; | ||
|
||
const browser = await puppeteer.launch({ | ||
args: [...chrome.args, "--hide-scrollbars", "--disable-web-security"], | ||
defaultViewport: chrome.defaultViewport, | ||
executablePath: await chrome.executablePath, | ||
ignoreHTTPSErrors: true, | ||
}); | ||
const page = await browser.newPage(); | ||
|
||
await page.goto(url); | ||
|
||
const profiles = await page.$$eval(".about-profiles__link", (items) => { | ||
const data = {}; | ||
items.forEach((item) => { | ||
data[item.getAttribute("title")] = item.getAttribute("href"); | ||
}); | ||
return Object.keys(data).length !== 0 ? data : { message: "No profiles found" }; | ||
}); | ||
|
||
await browser.close(); | ||
|
||
res.statusCode = 200; | ||
res.setHeader("Content-Type", `application/json`); | ||
res.end(JSON.stringify(profiles)); | ||
} catch (err) { | ||
console.log(err); | ||
res.statusCode = 500; | ||
res.json({ | ||
error: err.toString(), | ||
}); | ||
res.end(); | ||
} | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,4 @@ module.exports = async (req, res) => { | |
version: userAgent.toString(), | ||
}); | ||
res.end(); | ||
} | ||
}; |
2c0ed45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: