NekonekoID Kyouka commited on
Commit
47083b9
·
verified ·
1 Parent(s): f0b9221

Update index.js (#1)

Browse files

- Update index.js (8a27207928eb75ae2b696fe6afecf01d77b6bd06)


Co-authored-by: Hashiba <[email protected]>

Files changed (1) hide show
  1. index.js +21 -0
index.js CHANGED
@@ -147,7 +147,28 @@ app.all('/animelast', async (req, res) => {
147
  });
148
  });
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
 
 
 
 
 
 
 
151
 
152
  app.all('/stablediff/illusion', async (req, res) => {
153
  if (!['GET', 'POST'].includes(req.method)) return res.status(405).json({ success: false, message: 'Method Not Allowed' })
 
147
  });
148
  });
149
 
150
+ async function scrapeTitle(url) {
151
+ const browser = await chromium.launch();
152
+ const page = await browser.newPage();
153
+ await page.goto(url);
154
+ const title = await page.title();
155
+ await browser.close();
156
+ return title;
157
+ }
158
+
159
+ app.get('/scrape-title', async (req, res) => {
160
+ const url = req.query.url;
161
+ if (!url) {
162
+ return res.status(400).send('URL is required');
163
+ }
164
 
165
+ try {
166
+ const title = await scrapeTitle(url);
167
+ res.send({ title });
168
+ } catch (error) {
169
+ res.status(500).send('An error occurred while scraping the title');
170
+ }
171
+ });
172
 
173
  app.all('/stablediff/illusion', async (req, res) => {
174
  if (!['GET', 'POST'].includes(req.method)) return res.status(405).json({ success: false, message: 'Method Not Allowed' })