Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

[feat] improved the scrape for gdrive pdfs

rafaelsideguideb5045d166174
diff --git a/apps/api/src/scraper/WebScraper/custom/handleCustomScraping.ts b/apps/api/src/scraper/WebScraper/custom/handleCustomScraping.ts
index 5f6c34fe7..1301757d8 100644
--- a/apps/api/src/scraper/WebScraper/custom/handleCustomScraping.ts
+++ b/apps/api/src/scraper/WebScraper/custom/handleCustomScraping.ts
@@ -1,7 +1,9 @@
+import { fetchAndProcessPdf } from "../utils/pdfProcessor";
+
export async function handleCustomScraping(
text: string,
url: string
-): Promise<{ scraper: string; url: string; wait_after_load: number } | null> {
+): Promise<{ scraper: string; url: string; wait_after_load?: number } | null> {
// Check for Readme Docs special case
if (text.includes('<meta name="readme-deploy"')) {
console.log(
@@ -28,18 +30,21 @@ export async function handleCustomScraping(
// Check for Google Drive PDF links in the raw HTML
const googleDrivePdfPattern =
- /https:\/\/drive\.google\.com\/file\/d\/[^\/]+\/view/;
+ /https:\/\/drive\.google\.com\/file\/d\/([^\/]+)\/view/;
const googleDrivePdfLink = text.match(googleDrivePdfPattern);
if (googleDrivePdfLink) {
console.log(
`Google Drive PDF link detected for ${url}: ${googleDrivePdfLink[0]}`
);
+
+ const fileId = googleDrivePdfLink[1];
+ const pdfUrl = `https://drive.google.com/uc?export=download&id=${fileId}`;
+
return {
- scraper: "fire-engine",
- url: url,
- wait_after_load: 1000,
+ scraper: "pdf",
+ url: pdfUrl
};
}
-
+
return null;
}
diff --git a/apps/api/src/scraper/WebScraper/single_url.ts b/apps/api/src/scraper/WebScraper/single_url.ts
index 00c6958a7..10d32ce89 100644
--- a/apps/api/src/scraper/WebScraper/single_url.ts
+++ b/apps/api/src/scraper/WebScraper/single_url.ts
@@ -331,8 +331,13 @@ export async function scrapSingleUrl(
// Check for custom scraping conditions
const customScraperResult = await handleCustomScraping(text, url);
- if(customScraperResult){
- customScrapedContent = await scrapWithFireEngine(customScraperResult.url, customScraperResult.wait_after_load)
+ if (customScraperResult){
+ switch (customScraperResult.scraper) {
+ case "fire-engine":
+ customScrapedContent = await scrapWithFireEngine(customScraperResult.url, customScraperResult.wait_after_load)
+ case "pdf":
+ customScrapedContent = { html: await fetchAndProcessPdf(customScraperResult.url), screenshot }
+ }
}
if (customScrapedContent) {