Search Facebook Pages by Name

Site facebook.comTask search-facebook-pagesVersion v2Updated Nov 10, 2026Category social-media

Search Facebook's public Pages directory using its direct query URL and extract matching rendered Page candidates, observed Page URLs, and opaque numeric IDs without logging in or guessing identities. This skill was captured from a live agent session on facebook.com and is published here as a reusable recipe for agents.

NoteSelectors and URL schemes drift as sites change. A skill is a snapshot of what worked when it was captured, not a contract — agents re-learn it when it stops working.

Resolve a supplied {query} such as a brand, organization, or Page name to matching publicly rendered Facebook Page candidates. Return only names, descriptions, categories when visible, observed Facebook URLs, and numeric IDs present in the current search DOM. This is strictly read-only: do not log in, follow unrelated links, interact with results, or expose cookies, credentials, tokens, or private content.

Use Cases

  • The caller knows a Page name but not its Facebook URL or numeric Page ID.
  • The caller wants to check whether a likely Facebook Page exists for a brand or organization.
  • A later workflow needs an observed Page URL or opaque ID before opening a Page or Search the Facebook Ads Library by Page ID.
  • The caller wants several possible matches rather than assuming the first result is correct.
  • Use a consistent guest browser profile and residential proxy when Facebook presents consent, login, checkpoint, regional, or anti-bot content.

Automation Flow

  1. Navigate directly to the Page-search URL, URL-encoding the caller's value: https://www.facebook.com/search/pages/?q={urlencoded-query} Do not visit the Facebook homepage or type into a search box.

  2. Wait approximately 4–6 seconds for results to render, then run the evaluator below in the same browser-agent call. Select candidates using visible name, category, description, profile-image alt text, and observed Facebook URL; do not assume the first result is correct.

  3. Preserve each observed Page URL and numeric ID exactly. Numeric IDs may appear in routes such as /profile.php?id={numeric-id}, /people/{slug}/{numeric-id}/, or /{numeric-id}. Never derive an ID or slug from {query}.

  4. If more currently rendered results are requested and the list is progressively rendered, perform bounded downward scrolling, rerun the evaluator, and merge candidates by observed URL or ID. Stop when the list stabilizes or Facebook shows a login wall, consent wall, checkpoint, regional block, or sparse shell. Do not claim that unrendered Pages do not exist.

Run this self-contained evaluator on the loaded Facebook Page-search results:

(() => {
  const clean = v => (v || '').replace(/\s+/g, ' ').trim();
  const abs = href => { try { return new URL(href, location.href).href; } catch { return null; } };
  const visible = el => {
    if (!el) return false;
    const r = el.getBoundingClientRect(), s = getComputedStyle(el);
    return r.width > 0 && r.height > 0 && s.display !== 'none' && s.visibility !== 'hidden';
  };
  const pageUrl = href => {
    const u = abs(href);
    if (!u || !/^https?:\/\/www\.facebook\.com\//i.test(u)) return null;
    if (/\/(?:search|login|plugins|help|business|ads|marketplace)(?:\/|\?|$)/i.test(new URL(u).pathname)) return null;
    return u;
  };
  const idFrom = u => {
    try {
      const parsed = new URL(u), p = parsed.pathname;
      if (p === '/profile.php') return parsed.searchParams.get('id')?.match(/^\d{5,}$/)?.[0] || null;
      return p.match(/\/people\/[^/]+\/(\d{5,})\/?$/i)?.[1] ||
             p.match(/^\/(\d{5,})\/?$/)?.[1] || null;
    } catch { return null; }
  };
  const anchors = [...document.querySelectorAll('a[href]')]
    .filter(visible)
    .map(a => ({
      el: a,
      url: pageUrl(a.getAttribute('href')),
      text: clean(a.innerText || a.getAttribute('aria-label') || a.getAttribute('title'))
    }))
    .filter(x => x.url);
  const records = [], seen = new Set();
  for (const a of anchors) {
    let node = a.el, card = a.el;
    for (let i = 0; i < 8 && node; i++, node = node.parentElement) {
      const t = clean(node.innerText);
      if (t.length >= 20 && t.length <= 2500) card = node;
    }
    const cardText = clean(card.innerText);
    const id = idFrom(a.url);
    const key = a.url || id;
    if (!key || seen.has(key)) continue;
    seen.add(key);
    const lines = cardText.split(/\n+/).map(clean).filter(Boolean);
    const name = a.text || lines[0] || null;
    const description = lines.filter(x => x !== name).slice(0, 5).join(' ') || null;
    records.push({
      position: records.length + 1,
      name,
      url: a.url,
      page_id: id,
      description,
      card_text: cardText.slice(0, 2500)
    });
  }
  const title = clean(document.title);
  const body = clean(document.body?.innerText || '');
  const all = `${title} ${body}`;
  const params = Object.fromEntries(new URL(location.href).searchParams.entries());
  const login = /log in to facebook|log in or sign up|create an account|you must log in/i.test(all) && records.length === 0;
  const challenge = /security check|checkpoint|challenge|required to continue|confirm your identity/i.test(all) && records.length === 0;
  const consent = /cookie|consent|decline optional|only allow essential/i.test(body) && records.length === 0;
  const unavailable = /content isn't available|page isn't available|link may be broken/i.test(all) || (records.length === 0 && /^not found$/i.test(body));
  return {
    url: location.href,
    title,
    route: location.pathname,
    query: params.q || null,
    result_count: records.length,
    pages: records.slice(0, 100),
    login_required: login,
    challenge,
    consent_or_blocked: consent,
    unavailable,
    partial: login || challenge || consent || unavailable,
    partial_reason: challenge ? 'security_challenge_or_checkpoint' :
      login ? 'login_required' : consent ? 'consent_or_sparse_shell' :
      unavailable ? 'content_unavailable' : null,
    scroll: {
      y: Math.round(scrollY),
      viewport_height: innerHeight,
      document_height: Math.max(document.body?.scrollHeight || 0, document.documentElement?.scrollHeight || 0)
    }
  };
})()

Possible Friction Points

  • The durable Page-directory route is /search/pages/?q={urlencoded-query}; direct URL construction avoids a homepage visit and search-box interaction.
  • Page names, vanity slugs, and numeric IDs are not interchangeable. Use visible result evidence and observed links to disambiguate similarly named Pages.
  • Numeric IDs are opaque. Preserve an observed /profile.php?id={numeric-id}, /people/{slug}/{numeric-id}/, or /{numeric-id} route and never fabricate one from a name.
  • Facebook may return a sparse guest shell, login wall, consent prompt, checkpoint, regional response, or anti-bot page. Report the access limitation and do not bypass it or switch authentication contexts.
  • Logged-out sessions can receive a bare "Not Found" page instead of search results. Treat it as unavailable, not as evidence that no matching Pages exist.
  • Search results may be localized and progressively rendered. The evaluator reports only candidates currently present in the DOM; absence from this result set does not prove that no similar Page exists.
  • Generated React classes, IDs, and input identifiers are unstable. Prefer visible anchor text, semantic visibility checks, rendered card text, and observed href values.
  • A search result establishes only that Facebook rendered a candidate link. It does not prove ownership, authenticity, current activity, or authorization to use the Page's content.
  • Do not follow outbound links or expose cookies, access tokens, credentials, private profile data, or hidden Page state.

Example Result

{
  "url": "https://example.com/search?q=example",
  "title": "Example Title",
  "route": "/search",
  "query": "example",
  "result_count": 1,
  "pages": [
    {
      "position": 1,
      "name": "Example Title",
      "url": "https://example.com/profile",
      "page_id": null,
      "description": "Example description",
      "card_text": "Example Title Example description"
    }
  ],
  "login_required": false,
  "challenge": false,
  "consent_or_blocked": false,
  "unavailable": false,
  "partial": false,
  "partial_reason": null,
  "scroll": {
    "y": 0,
    "viewport_height": 800,
    "document_height": 1200
  }
}

Call it

GET https://production-sfo.browserless.io/skills?token=TOKEN-HERE&domain=facebook.com&task=search-facebook-pages