π¬ Extract structured data from webpages with Apify and OpenAI
β‘ 104 views Β· π¬ Document Extraction & Analysis
π‘ Pro Tip β HTTP Request scraping tends to break when sites update their markup. If youβre scraping a major platform, check if ScraperNode covers it β it has maintained scrapers for LinkedIn, Instagram, TikTok, YouTube, and 20+ other platforms that return structured data.
Description
Quick overview
This workflow exposes a webhook that finds or accepts a target webpage, scrapes it to clean Markdown using Apify, and uses OpenAI with a dynamic schema to return structured JSON fields requested by the caller.
How it works
- Receives a POST webhook request containing either a direct
target_urlor asubject+website_domain, plus a requiredtarget_dataarray of fields to extract. - Validates that
target_datais provided and returns a 400 response if it is missing or empty. - Resolves the page URL by using the provided
target_urlor running an Apify Google Search Scrapersite:query and taking the first organic result. - If no matching URL is found, returns a 404 response to the caller.
- Scrapes the resolved URL with Apify Website Content Crawler (optionally using provided cookies) and normalizes the returned Markdown and content length.
- If the scraped content is too short, returns a 200 response with
success:falseindicating no content could be extracted. - Sends the page content and requested field definitions to OpenAI and returns a 200 response with the extracted fields as structured JSON (using βNAβ for missing values).
Setup
- Create an Apify account and add an n8n Header Auth credential that sends
Authorization: Bearer <APIFY_TOKEN>, then select it on both Apify HTTP Request steps. - Add an OpenAI API credential and select it for the OpenAI chat model used for extraction.
- Configure the webhook path in your calling app and send a JSON body with
target_dataplus eithertarget_urlorsubjectandwebsite_domain(and optionalcookies). - Adjust defaults such as crawler type, crawl limits, timeouts, and minimum content length in the workflowβs configuration values if needed.
Additional info
Extract structured data from any webpage using Apify and AI
π₯ Open full documentation on Notion
Need help customizing?
Contact me for consulting and support : Linkedin
MY NEW YOUTUBE CHANNEL
π Subscribe to my new YouTube channel. Here Iβll share videos and Shorts with practical tutorials and FREE templates for n8n.
π Nodes Used
HTTP Request, Webhook, AI Agent, OpenAI Chat Model, Structured Output Parser
π₯ Import
Download workflow.json and import into n8n:
Workflow menu β Import from File
