Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

fix: improve `FACEBOOK_REGEX` to match older style page URLs (#2650)

Joe Leonarda005e699682c
diff --git a/packages/utils/src/internals/social.ts b/packages/utils/src/internals/social.ts
index c825fdb01..f9f6272d5 100644
--- a/packages/utils/src/internals/social.ts
+++ b/packages/utils/src/internals/social.ts
@@ -180,7 +180,7 @@ const TWITTER_REGEX_STRING = `(?<!\\w)(?:http(?:s)?:\\/\\/)?(?:www.)?(?:twitter.
const FACEBOOK_RESERVED_PATHS =
'rsrc\\.php|apps|groups|events|l\\.php|friends|images|photo.php|chat|ajax|dyi|common|policies|login|recover|reg|help|security|messages|marketplace|pages|live|bookmarks|games|fundraisers|saved|gaming|salesgroups|jobs|people|ads|ad_campaign|weather|offers|recommendations|crisisresponse|onthisday|developers|settings|connect|business|plugins|intern|sharer';
-const FACEBOOK_REGEX_STRING = `(?<!\\w)(?:http(?:s)?:\\/\\/)?(?:www.)?(?:facebook.com|fb.com)\\/(?!(?:${FACEBOOK_RESERVED_PATHS})(?:[\\'\\"\\?\\.\\/]|$))(profile\\.php\\?id\\=[0-9]{3,20}|(?!profile\\.php)[a-z0-9\\.]{5,51})(?![a-z0-9\\.])(?:/)?`;
+const FACEBOOK_REGEX_STRING = `(?<!\\w)(?:http(?:s)?:\\/\\/)?(?:www.)?(?:facebook.com|fb.com)\\/(?!(?:${FACEBOOK_RESERVED_PATHS})(?:[\\'\\"\\?\\.\\/]|$))(profile\\.php\\?id\\=[0-9]{3,20}|(?!profile\\.php)[a-z0-9-\\.]{5,51})(?![a-z0-9\\.])(?:/)?`;
const YOUTUBE_REGEX_STRING =
'(?<!\\w)(?:https?:\\/\\/)?(?:youtu\\.be\\/|(?:www\\.|m\\.)?youtube\\.com(?:\\/(?:watch|v|embed|user|c(?:hannel)?)(?:\\.php)?)?(?:\\?[^ ]*v=|\\/))([a-zA-Z0-9\\-_]{2,100})';
diff --git a/test/utils/social.test.ts b/test/utils/social.test.ts
index 11f1c3866..96c140667 100644
--- a/test/utils/social.test.ts
+++ b/test/utils/social.test.ts
@@ -779,6 +779,8 @@ describe('utils.social', () => {
expect(FACEBOOK_REGEX.test('https://www.facebook.com/someusername')).toBe(true);
expect(FACEBOOK_REGEX.test('https://www.facebook.com/someusername/')).toBe(true);
+ expect(FACEBOOK_REGEX.test('https://www.facebook.com/some-username-1234')).toBe(true);
+ expect(FACEBOOK_REGEX.test('https://www.facebook.com/some-username-1234/')).toBe(true);
expect(FACEBOOK_REGEX.test('http://www.facebook.com/some.username123')).toBe(true);
expect(FACEBOOK_REGEX.test('www.facebook.com/someusername')).toBe(true);
expect(FACEBOOK_REGEX.test('facebook.com/someusername')).toBe(true);