Skip to content

Instantly share code, notes, and snippets.

@wesbos
Created January 25, 2019 20:30
Show Gist options
  • Save wesbos/4d05bcc6aac16866259e818de1d1c4ad to your computer and use it in GitHub Desktop.
Save wesbos/4d05bcc6aac16866259e818de1d1c4ad to your computer and use it in GitHub Desktop.

Revisions

  1. wesbos created this gist Jan 25, 2019.
    45 changes: 45 additions & 0 deletions facebookScrape.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    require('isomorphic-fetch');

    async function go(params) {
    const variables = {
    params: {
    bqf: { callsite: 'COMMERCE_MKTPLACE_WWW', query: 'iphone' },
    browse_request_params: {
    // burlington
    filter_location_id: '108043585884666',
    // hamilton
    // filter_location_id: '104011556303312',
    filter_price_lower_bound: 0,
    filter_price_upper_bound: 214748364700,
    },
    custom_request_params: {
    surface: 'SEARCH',
    search_vertical: 'C2C',
    },
    },
    };

    const res = await fetch('https://www.facebook.com/api/graphql/', {
    headers: {
    'content-type': 'application/x-www-form-urlencoded',
    },
    body: `variables=${JSON.stringify(variables)}&doc_id=2022753507811174`,
    method: 'POST',
    mode: 'cors',
    });
    const { data } = await res.json();
    console.log(data);
    // Pagination Cursor - doesn't seem to work if I pass it above
    console.log(data.marketplace_search.feed_units.page_info);
    data.marketplace_search.feed_units.edges.forEach(
    ({
    node: {
    product_item: { for_sale_item },
    },
    }) => {
    console.log(for_sale_item.group_commerce_item_title);
    }
    );
    }

    go();