AI-assisted web scraping with GPT-4o: OpenAI’s new structured outputs feature in their API has opened up exciting possibilities for AI-assisted web scraping, as demonstrated by a recent experiment using GPT-4o.
Initial approach and model selection:
- The experiment utilized Pydantic models to define the structure for parsed columns and tables
- A system prompt was crafted to instruct GPT-4o on its role as an expert web scraper
- GPT-4o outperformed GPT-4o mini in parsing accuracy, leading to its selection for further experimentation
Performance on complex tables:
- GPT-4o successfully parsed a 10-day weather forecast table from Weather.com, correctly handling varying row sizes and hidden data
- The model accurately extracted day and night forecasts, demonstrating its ability to interpret complex table structures
- Interestingly, GPT-4o parsed “Condition” data that was present in the source code but not visible on the website
Challenges with merged rows:
- Tables from Wikipedia with merged rows posed difficulties for the model
- Attempts to modify the system prompt to handle collapsed rows were unsuccessful
- Further experimentation is needed to improve the model’s performance on tables with merged cells
XPath generation approach:
- To reduce API call costs, an attempt was made to have GPT-4o generate XPaths instead of parsed data
- This method proved less reliable, often resulting in invalid or incorrect XPaths
Combined extraction and XPath generation:
- A two-step approach was developed: first extracting data, then using it as a reference to generate XPaths
- This combined method yielded better results than directly asking for XPaths
- Retry logic was implemented to handle cases where generated XPaths returned no results
- Issues arose when the model converted image data to text, causing mismatches in the second step
Cost considerations and optimizations:
- GPT-4o usage for web scraping can become expensive due to the large amount of text in HTML tables
- A cleanup function was implemented to remove unnecessary HTML attributes, reducing character count by half without degrading performance
- Further optimizations, such as generating multiple XPaths per API call, are being considered
Demo and future improvements:
- A Streamlit demo was created to showcase the AI-assisted web scraping tool
- Potential enhancements include capturing browser events for better user experience, developing more complex extraction methods for intricate tables, and further optimizing HTML cleanup to reduce API costs
Broader implications: While GPT-4o shows promise in AI-assisted web scraping, the high costs associated with its use present a significant challenge. This experiment highlights both the potential and limitations of using large language models for data extraction tasks, suggesting that further refinements in efficiency and cost-effectiveness are necessary for widespread adoption in web scraping applications.
Recent Stories
DOE fusion roadmap targets 2030s commercial deployment as AI drives $9B investment
The Department of Energy has released a new roadmap targeting commercial-scale fusion power deployment by the mid-2030s, though the plan lacks specific funding commitments and relies on scientific breakthroughs that have eluded researchers for decades. The strategy emphasizes public-private partnerships and positions AI as both a research tool and motivation for developing fusion energy to meet data centers' growing electricity demands. The big picture: The DOE's roadmap aims to "deliver the public infrastructure that supports the fusion private sector scale up in the 2030s," but acknowledges it cannot commit to specific funding levels and remains subject to Congressional appropriations. Why...
Oct 17, 2025Tying it all together: Credo’s purple cables power the $4B AI data center boom
Credo, a Silicon Valley semiconductor company specializing in data center cables and chips, has seen its stock price more than double this year to $143.61, following a 245% surge in 2024. The company's signature purple cables, which cost between $300-$500 each, have become essential infrastructure for AI data centers, positioning Credo to capitalize on the trillion-dollar AI infrastructure expansion as hyperscalers like Amazon, Microsoft, and Elon Musk's xAI rapidly build out massive computing facilities. What you should know: Credo's active electrical cables (AECs) are becoming indispensable for connecting the massive GPU clusters required for AI training and inference. The company...
Oct 17, 2025Vatican launches Latin American AI network for human development
The Vatican hosted a two-day conference bringing together 50 global experts to explore how artificial intelligence can advance peace, social justice, and human development. The event launched the Latin American AI Network for Integral Human Development and established principles for ethical AI governance that prioritize human dignity over technological advancement. What you should know: The Pontifical Academy of Social Sciences, the Vatican's research body for social issues, organized the "Digital Rerum Novarum" conference on October 16-17, combining academic research with practical AI applications. Participants included leading experts from MIT, Microsoft, Columbia University, the UN, and major European institutions. The conference...