Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
@@ -62,6 +62,29 @@ app.post('/imagetopdf', async (req, res) => {
|
|
62 |
}
|
63 |
})
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
app.get('/fetch', async (req, res) => {
|
66 |
try {
|
67 |
if (!req.query.url) return res.json({ message: 'Required an url' })
|
|
|
62 |
}
|
63 |
})
|
64 |
|
65 |
+
async function scrapeTitle(url) {
|
66 |
+
const browser = await chromium.launch();
|
67 |
+
const page = await browser.newPage();
|
68 |
+
await page.goto(url);
|
69 |
+
const title = await page.title();
|
70 |
+
await browser.close();
|
71 |
+
return title;
|
72 |
+
}
|
73 |
+
|
74 |
+
app.get('/scrape-title', async (req, res) => {
|
75 |
+
const url = req.query.url;
|
76 |
+
if (!url) {
|
77 |
+
return res.status(400).send('URL is required');
|
78 |
+
}
|
79 |
+
|
80 |
+
try {
|
81 |
+
const title = await scrapeTitle(url);
|
82 |
+
res.send({ title });
|
83 |
+
} catch (error) {
|
84 |
+
res.status(500).send('An error occurred while scraping the title');
|
85 |
+
}
|
86 |
+
});
|
87 |
+
|
88 |
app.get('/fetch', async (req, res) => {
|
89 |
try {
|
90 |
if (!req.query.url) return res.json({ message: 'Required an url' })
|