{"id":17771,"date":"2026-08-15T13:31:16","date_gmt":"2026-08-15T13:31:16","guid":{"rendered":"https:\/\/techtrendfeed.com\/?p=17771"},"modified":"2026-08-15T13:31:16","modified_gmt":"2026-08-15T13:31:16","slug":"tips-on-how-to-construct-a-easy-ai-internet-scraper-with-python","status":"publish","type":"post","link":"https:\/\/techtrendfeed.com\/?p=17771","title":{"rendered":"Tips on how to Construct a Easy AI Internet Scraper with Python"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div id=\"post-\">\n<p><img decoding=\"async\" alt=\"How to Build a Simple AI Web Scraper with Python\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/awan_build_simple_ai_web_scraper_python_5.png\"\/><br \/>\u00a0 <\/p>\n<p>Internet scraping is the method of amassing data from web sites routinely. A traditional scraper normally extracts uncooked textual content, HTML parts, or the complete web page content material. However when you&#8217;re constructing AI brokers or massive language mannequin (LLM) purposes, sending the whole webpage to the mannequin will not be all the time the very best strategy.<\/p>\n<p>A greater means is to first clear the web page, convert it into Markdown, after which use an LLM to grasp the content material and return solely the reply the consumer wants. This makes the output cleaner, simpler to learn, and simpler to make use of in one other workflow.<\/p>\n<p>It additionally helps cut back token utilization. As an alternative of passing a messy webpage stuffed with navigation hyperlinks, buttons, scripts, footers, and repeated content material, we solely ship the helpful web page content material to the mannequin. The LLM then returns a centered reply in Markdown as an alternative of dumping the entire web page again to the consumer.<\/p>\n<p>On this information, we are going to construct a easy AI internet scraper in Python utilizing Jupyter Pocket book. It is going to fetch a webpage, clear the HTML, convert it into Markdown, settle for a consumer question, and return a transparent Markdown reply primarily based on the web page content material.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Setting Up<\/h2>\n<p>\u00a0<br \/>We are going to use Jupyter Pocket book for this challenge. It makes it simpler to check every step first earlier than turning the scraper into a correct software programming interface (API) or software.<\/p>\n<p>Begin by putting in the required Python packages:<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>!pip set up requests beautifulsoup4 markdownify openai ftfy python-dotenv<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>We are going to use:<\/p>\n<p>Within the subsequent cell, import the required libraries:<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>import os&#13;\nimport re&#13;\nimport requests&#13;\n&#13;\nfrom bs4 import BeautifulSoup, Remark&#13;\nfrom ftfy import fix_text&#13;\nfrom markdownify import markdownify as markdownify_html&#13;\nfrom openai import OpenAI&#13;\nfrom dotenv import load_dotenv&#13;\nfrom IPython.show import Markdown, show<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Subsequent, make sure that your OpenAI API key&#8217;s accessible as an atmosphere variable. The safer means is to create a <code style=\"background: #F5F5F5;\">.env<\/code> file in the identical folder as your pocket book and add your key there:<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>OPENAI_API_KEY=your_api_key_here<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Then load it contained in the pocket book:<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>load_dotenv()&#13;\n&#13;\nshopper = OpenAI(api_key=os.getenv(\"OPENAI_API_KEY\"))<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>You may also examine that the important thing was loaded accurately:<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>if not os.getenv(\"OPENAI_API_KEY\"):&#13;\n    elevate ValueError(\"OPENAI_API_KEY is lacking. Add it to your .env file first.\")<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Additionally make sure that your OpenAI platform account has billing arrange. For brand new API accounts, it&#8217;s possible you&#8217;ll want so as to add pay as you go credit earlier than you&#8217;ll be able to run API calls. If a mannequin will not be accessible in your account, use one other mannequin out of your OpenAI dashboard.<\/p>\n<p>Now outline the mannequin identify:<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>MODEL_NAME = \"gpt-5.4-nano\"<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>We&#8217;re utilizing a smaller mannequin right here as a result of this job doesn&#8217;t want a big reasoning mannequin. The purpose is straightforward: learn the cleaned webpage content material, perceive the consumer question, and return a centered Markdown reply.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Fetching the Webpage<\/h2>\n<p>\u00a0<br \/>Now we are going to create the primary operate. This operate will fetch the webpage utilizing the <code style=\"background: #F5F5F5;\">requests<\/code> package deal and return the uncooked HTML.<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>def fetch_page(url: str) -&gt; str:&#13;\n    \"\"\"&#13;\n    Obtain the HTML content material from a webpage.&#13;\n    \"\"\"&#13;\n    headers = {&#13;\n        \"Consumer-Agent\": \"SimpleAIScraper\/1.0\"&#13;\n    }&#13;\n&#13;\n    response = requests.get(url, headers=headers, timeout=15)&#13;\n    response.raise_for_status()&#13;\n&#13;\n    return response.textual content<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>The <code style=\"background: #F5F5F5;\">Consumer-Agent<\/code> header tells the web site that the request is coming from our scraper. Some web sites block requests that don&#8217;t embrace a consumer agent, so including one makes the request a bit extra dependable.<\/p>\n<p>We additionally use <code style=\"background: #F5F5F5;\">timeout<\/code> to keep away from ready indefinitely if the web site doesn&#8217;t reply. The <code style=\"background: #F5F5F5;\">raise_for_status()<\/code> name will cease the code if the request fails \u2014 for instance, if the web page returns a <code style=\"background: #F5F5F5;\">404<\/code> or <code style=\"background: #F5F5F5;\">500<\/code> error.<\/p>\n<p>Now let&#8217;s take a look at the operate with an actual web site:<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>uncooked = fetch_page(\"https:\/\/www.olostep.com\/\")&#13;\nprint(uncooked[:500])<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>This can obtain the uncooked HTML from the webpage and print the primary 500 characters.<\/p>\n<p>\u00a0<\/p>\n<p><center><img decoding=\"async\" alt=\"Raw HTML output from the fetch_page function\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/awan_build_simple_ai_web_scraper_python_1.png\"\/><br \/><span>Uncooked HTML output | Picture by Writer<\/span><\/center><br \/>\n\u00a0<\/p>\n<p>At this stage, the output will nonetheless look messy as a result of it incorporates the complete web page HTML, together with tags, scripts, format parts, and different content material we don&#8217;t want.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Cleansing the HTML<\/h2>\n<p>\u00a0<br \/>The uncooked HTML from a webpage normally incorporates loads of content material we don&#8217;t want. It will possibly embrace scripts, styling, navigation menus, buttons, kinds, headers, footers, popups, and different format parts.<\/p>\n<p>Earlier than sending the web page content material to the LLM, we have to clear the HTML. This helps cut back noise and makes the ultimate Markdown a lot simpler for the mannequin to grasp.<\/p>\n<p>We are going to use BeautifulSoup to parse the HTML and take away pointless parts.<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>def clean_html(html):&#13;\n    html = fix_text(html)&#13;\n&#13;\n    soup = BeautifulSoup(html, \"html.parser\")&#13;\n&#13;\n    # Take away apparent noisy tags&#13;\n    for tag in soup([&#13;\n        \"script\", \"style\", \"noscript\", \"svg\", \"img\", \"iframe\",&#13;\n        \"nav\", \"header\", \"footer\", \"aside\", \"form\", \"button\"&#13;\n    ]):&#13;\n        tag.decompose()&#13;\n&#13;\n    noise_words = [&#13;\n        \"cursor\",&#13;\n        \"modal\",&#13;\n        \"popup\",&#13;\n        \"floating\",&#13;\n        \"signup\",&#13;\n        \"login\",&#13;\n        \"cookie\",&#13;\n        \"banner\",&#13;\n        \"navbar\",&#13;\n        \"menu\",&#13;\n        \"footer\",&#13;\n        \"header\",&#13;\n        \"subscribe\",&#13;\n        \"newsletter\",&#13;\n        \"loading\",&#13;\n        \"wait\",&#13;\n        \"success\",&#13;\n        \"auth\",&#13;\n        \"w-nav\",&#13;\n        \"w-form\"&#13;\n    ]&#13;\n&#13;\n    # First accumulate noisy tags&#13;\n    tags_to_remove = []&#13;\n&#13;\n    for tag in soup.find_all(True):&#13;\n        if tag.attrs is None:&#13;\n            proceed&#13;\n&#13;\n        class_value = tag.get(\"class\", [])&#13;\n        id_value = tag.get(\"id\", \"\")&#13;\n&#13;\n        if isinstance(class_value, record):&#13;\n            class_text = \" \".be part of(class_value).decrease()&#13;\n        else:&#13;\n            class_text = str(class_value).decrease()&#13;\n&#13;\n        id_text = str(id_value).decrease()&#13;\n&#13;\n        if any(phrase in class_text or phrase in id_text for phrase in noise_words):&#13;\n            tags_to_remove.append(tag)&#13;\n&#13;\n    # Then take away them safely&#13;\n    for tag in tags_to_remove:&#13;\n        tag.decompose()&#13;\n&#13;\n    physique = soup.physique if soup.physique else soup&#13;\n&#13;\n    return str(physique)<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>First, we use <code style=\"background: #F5F5F5;\">fix_text()<\/code> to scrub any damaged or unusual textual content encoding points. Then BeautifulSoup parses the HTML so we are able to take away the elements we don&#8217;t want.<\/p>\n<p>We take away apparent noisy tags like <code style=\"background: #F5F5F5;\">script<\/code>, <code style=\"background: #F5F5F5;\">type<\/code>, <code style=\"background: #F5F5F5;\">nav<\/code>, <code style=\"background: #F5F5F5;\">header<\/code>, <code style=\"background: #F5F5F5;\">footer<\/code>, <code style=\"background: #F5F5F5;\">type<\/code>, and <code style=\"background: #F5F5F5;\">button<\/code>. These sections normally don&#8217;t assist reply the consumer question and might waste tokens.<\/p>\n<p>After that, we search for noisy class names and IDs. Many web sites use phrases like <code style=\"background: #F5F5F5;\">popup<\/code>, <code style=\"background: #F5F5F5;\">cookie<\/code>, <code style=\"background: #F5F5F5;\">navbar<\/code>, <code style=\"background: #F5F5F5;\">publication<\/code>, or <code style=\"background: #F5F5F5;\">modal<\/code> inside their HTML. If a tag incorporates these phrases, we accumulate it and take away it safely.<\/p>\n<p>Now let&#8217;s run the operate on the uncooked HTML:<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>clear = clean_html(uncooked)&#13;\nprint(clear[:500])<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>As you&#8217;ll be able to see, the webpage is now a lot cleaner. It nonetheless incorporates helpful HTML tags and textual content, however a lot of the noisy format, scripts, navigation, and popups have been eliminated.<\/p>\n<p>\u00a0<\/p>\n<p><center><img decoding=\"async\" alt=\"Cleaned HTML output after removing noisy elements\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/awan_build_simple_ai_web_scraper_python_2.png\"\/><br \/><span>Cleaned HTML output | Picture by Writer<\/span><\/center><br \/>\n\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Changing HTML to Markdown<\/h2>\n<p>\u00a0<br \/>Now we are going to convert the cleaned HTML into Markdown. Markdown is simpler to learn, simpler to avoid wasting, and simpler for the LLM to grasp in comparison with uncooked HTML.<\/p>\n<p>This step additionally helps cut back enter tokens as a result of we take away pointless formatting, photographs, clean strains, and repeated textual content. For the conversion, we are going to use markdownify.<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>def html_to_markdown(html):&#13;\n    markdown_text = markdownify_html(&#13;\n        html,&#13;\n        heading_style=\"ATX\",&#13;\n        bullets=\"-\"&#13;\n    )&#13;\n&#13;\n    markdown_text = fix_text(markdown_text)&#13;\n&#13;\n    # Take away picture markdown&#13;\n    markdown_text = re.sub(r\"![.*?](.*?)\", \"\", markdown_text)&#13;\n&#13;\n    # Take away additional areas and clean strains&#13;\n    markdown_text = re.sub(r\"[ t]+\", \" \", markdown_text)&#13;\n    markdown_text = re.sub(r\"n{3,}\", \"nn\", markdown_text)&#13;\n&#13;\n    strains = []&#13;\n&#13;\n    skip_lines = [&#13;\n        \"click to try\",&#13;\n        \"wait...\",&#13;\n        \"you've successfully reserved your spot.\",&#13;\n        \"thank you! your submission has been received!\",&#13;\n        \"oops! something went wrong while submitting the form.\",&#13;\n        \"product\",&#13;\n        \"resources\",&#13;\n        \"company\"&#13;\n    ]&#13;\n&#13;\n    for line in markdown_text.splitlines():&#13;\n        line = line.strip()&#13;\n&#13;\n        if not line:&#13;\n            proceed&#13;\n&#13;\n        if line.decrease() in skip_lines:&#13;\n            proceed&#13;\n&#13;\n        strains.append(line)&#13;\n&#13;\n    return \"n\".be part of(strains)<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>First, we use markdownify to transform the cleaned HTML into Markdown. We set the heading type to <code style=\"background: #F5F5F5;\">ATX<\/code>, which implies headings will use customary Markdown syntax with <code style=\"background: #F5F5F5;\">#<\/code>, <code style=\"background: #F5F5F5;\">##<\/code>, and <code style=\"background: #F5F5F5;\">###<\/code>.<\/p>\n<p>Then we run <code style=\"background: #F5F5F5;\">fix_text()<\/code> once more to scrub any remaining encoding points. After that, we take away picture Markdown as a result of picture hyperlinks are normally not helpful for answering text-based questions.<\/p>\n<p>We additionally take away additional areas and clean strains so the ultimate content material is compact. This makes the web page simpler to examine and helps cut back the variety of tokens despatched to the mannequin.<\/p>\n<p>The <code style=\"background: #F5F5F5;\">skip_lines<\/code> record removes repeated web site textual content equivalent to type messages, navigation labels, and small call-to-action textual content. You possibly can replace this record primarily based on the web site you might be scraping.<\/p>\n<p>Now let&#8217;s run the operate:<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>md = html_to_markdown(clear)&#13;\nprint(md[:500])<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>As you&#8217;ll be able to see, the textual content is now a lot cleaner and nearer to the format we would like. As an alternative of uncooked HTML, we now have readable Markdown with helpful headings, paragraphs, and bullet factors.<\/p>\n<p>\u00a0<\/p>\n<p><center><img decoding=\"async\" alt=\"Markdown output after converting cleaned HTML\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/awan_build_simple_ai_web_scraper_python_6.png\"\/><br \/><span>Markdown output | Picture by Writer<\/span><\/center><br \/>\n\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Asking a Consumer Question In opposition to the Web page<\/h2>\n<p>\u00a0<br \/>Now we are going to create the operate that sends the cleaned Markdown content material to the LLM. This operate takes two inputs: the webpage content material in Markdown and the consumer question.<\/p>\n<p>As an alternative of asking the mannequin to summarize the entire web page, we ask it to reply a particular query utilizing solely the web page content material. This makes the response extra centered and helpful.<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>def answer_query_from_page(markdown_text, user_query):&#13;\n    immediate = f\"\"\"&#13;\nYou might be an AI internet scraping assistant.&#13;\n&#13;\nYou'll obtain Markdown extracted from a webpage.&#13;\n&#13;\nYour job is to reply the consumer's question utilizing solely the helpful web page content material.&#13;\n&#13;\nConsumer question:&#13;\n{user_query}&#13;\n&#13;\nWebpage Markdown:&#13;\n{markdown_text}&#13;\n&#13;\nDirections:&#13;\n- Return solely clear Markdown.&#13;\n- Use solely data from the webpage Markdown.&#13;\n- Don't invent lacking particulars.&#13;\n- Ignore navigation hyperlinks, buttons, CTAs, popups, ornamental labels, picture captions, and repeated advertising and marketing fragments.&#13;\n- Ignore strains like \"Begin at no cost\", \"Contact Gross sales\", \"Your AI Agent\", and ornamental workflow examples except they immediately reply the question.&#13;\n- Concentrate on headings, paragraphs, product descriptions, function sections, pricing particulars, documentation textual content, and factual claims.&#13;\n- If the web page doesn't include the reply, say: \"The web page doesn't include this data.\"&#13;\n- Maintain the reply brief, clear, and centered.&#13;\n\"\"\"&#13;\n&#13;\n    response = shopper.responses.create(&#13;\n        mannequin=MODEL_NAME,&#13;\n        enter=immediate&#13;\n    )&#13;\n&#13;\n    return response.output_text<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>The immediate is a very powerful a part of this step. It tells the mannequin what function it ought to play, what content material it could possibly use, and how much reply it ought to return.<\/p>\n<p>We additionally inform the mannequin to make use of solely the supplied Markdown. That is necessary as a result of we don&#8217;t want the mannequin to guess or add data that&#8217;s not current on the webpage.<\/p>\n<p>The instruction to return solely clear Markdown makes the output simpler to show in a pocket book, save to a file, or cross into one other AI workflow.<\/p>\n<p>This operate is the place the AI internet scraper turns into genuinely helpful. We&#8217;re not simply extracting web page textual content \u2014 we&#8217;re asking the LLM to grasp the cleaned web page and return the precise reply the consumer is searching for.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Creating the Full AI Internet Scraper<\/h2>\n<p>\u00a0<br \/>Now we are going to create the ultimate operate that connects the whole lot collectively.<\/p>\n<p>This operate will take the URL and the consumer question as inputs. It is going to then fetch the webpage, clear the HTML, convert the content material into Markdown, and return the reply utilizing the <code style=\"background: #F5F5F5;\">gpt-5.4-nano<\/code> mannequin.<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>def ai_web_scraper(url, user_query):&#13;\n    raw_html = fetch_page(url)&#13;\n    cleaned_html = clean_html(raw_html)&#13;\n    markdown_text = html_to_markdown(cleaned_html)&#13;\n    reply = answer_query_from_page(markdown_text, user_query)&#13;\n&#13;\n    return reply<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>That is our full AI internet scraper pipeline. As an alternative of manually working every step one after the other, we are able to now name a single operate and get a clear Markdown reply from any webpage.<\/p>\n<p>The move is straightforward:<\/p>\n<ul>\n<li>Fetch the webpage.\n<\/li>\n<li>Clear the HTML.\n<\/li>\n<li>Convert it into Markdown.\n<\/li>\n<li>Ask the LLM a query.\n<\/li>\n<li>Return the ultimate reply.\n<\/li>\n<\/ul>\n<p>This retains the code easy and straightforward to reuse later in an API, chatbot, or agent workflow.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Testing the AI Internet Scraper<\/h2>\n<p>\u00a0<br \/>Now let&#8217;s take a look at our AI internet scraper. We are going to present it with an internet site URL and ask what the corporate does.<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>url = \"https:\/\/www.olostep.com\/\"&#13;\nuser_query = \"What does this firm do?\"&#13;\noutcome = ai_web_scraper(url, user_query)&#13;\n&#13;\nshow(Markdown(outcome))<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>In return, we get a correct Markdown response concerning the firm and its product. That is significantly better than returning the complete webpage content material as a result of the reply is concentrated, readable, and immediately associated to the consumer question.<\/p>\n<p>\u00a0<\/p>\n<p><center><img decoding=\"async\" alt=\"AI web scraper output answering what the company does\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/awan_build_simple_ai_web_scraper_python_4.png\"\/><br \/><span>Scraper output for a corporation overview question | Picture by Writer<\/span><\/center><br \/>\n\u00a0<\/p>\n<p>Now let&#8217;s strive a unique web page and ask about pricing.<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>url = \"https:\/\/www.olostep.com\/pricing\"&#13;\nuser_query = \"Assist me perceive the pricing\"&#13;\noutcome = ai_web_scraper(url, user_query)&#13;\n&#13;\nshow(Markdown(outcome))<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>In just a few seconds, we get a clear response that&#8217;s straightforward to grasp. As an alternative of manually visiting the pricing web page and looking for the related data, the scraper extracts the web page, cleans it, and asks the LLM to elucidate solely what issues.<\/p>\n<p>\u00a0<\/p>\n<p><center><img decoding=\"async\" alt=\"AI web scraper output summarizing pricing information\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/awan_build_simple_ai_web_scraper_python_3.png\"\/><br \/><span>Scraper output for a pricing question | Picture by Writer<\/span><\/center><br \/>\n\u00a0<\/p>\n<p>We are able to additionally save the ultimate response as a Markdown file.<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>with open(\"ai_scraper_result.md\", \"w\", encoding=\"utf-8\") as file:&#13;\n    file.write(outcome)&#13;\n&#13;\nprint(\"Markdown saved to ai_scraper_result.md\")<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Output:<\/p>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>Markdown saved to ai_scraper_result.md<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Now the result&#8217;s saved as a Markdown file, which you&#8217;ll be able to open, edit, share, or use in one other workflow.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Remaining Ideas<\/h2>\n<p>\u00a0<br \/>Constructing your personal AI instruments is way simpler now. With just a few strains of Python and an LLM, we turned a traditional webpage right into a easy question-answering engine that may learn the web page, perceive the consumer question, and return a clear Markdown reply.<\/p>\n<p>That is highly effective as a result of you don&#8217;t all the time want a fancy system to unravel a particular drawback. Typically, a small specialised answer is sufficient.<\/p>\n<p>However it&#8217;s also necessary to keep in mind that the whole lot has a price. Operating the app on a server prices cash. Calling an LLM prices cash. Sustaining the scraper, fixing damaged pages, dealing with errors, and bettering the system over time additionally prices money and time.<\/p>\n<p>So earlier than constructing your personal customized answer, it&#8217;s price  current instruments like <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/www.olostep.com\/\" target=\"_blank\">Olostep<\/a><\/strong>, <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/www.firecrawl.dev\/\" target=\"_blank\">Firecrawl<\/a><\/strong>, or <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/exa.ai\/\" target=\"_blank\">Exa<\/a><\/strong>. In some instances, paying for a ready-made scraping or internet intelligence API might make extra sense. In different instances \u2014 particularly if the duty is small, native, or very particular \u2014 constructing your personal light-weight answer could be the higher choice.<br \/>\u00a0<br \/>\u00a0<\/p>\n<p><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/abid.work\" rel=\"noopener\"><b><strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/abid.work\" target=\"_blank\" rel=\"noopener noreferrer\">Abid Ali Awan<\/a><\/strong><\/b><\/a> (<a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/www.linkedin.com\/in\/1abidaliawan\" rel=\"noopener\">@1abidaliawan<\/a>) is a licensed information scientist skilled who loves constructing machine studying fashions. Presently, he&#8217;s specializing in content material creation and writing technical blogs on machine studying and information science applied sciences. Abid holds a Grasp&#8217;s diploma in know-how administration and a bachelor&#8217;s diploma in telecommunication engineering. His imaginative and prescient is to construct an AI product utilizing a graph neural community for college kids battling psychological sickness.<\/p>\n<\/p><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 Internet scraping is the method of amassing data from web sites routinely. A traditional scraper normally extracts uncooked textual content, HTML parts, or the complete web page content material. However when you&#8217;re constructing AI brokers or massive language mannequin (LLM) purposes, sending the whole webpage to the mannequin will not be all the time [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":17773,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[73,1258,10178,4127,505],"class_list":["post-17771","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning","tag-build","tag-python","tag-scraper","tag-simple","tag-web"],"_links":{"self":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/17771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17771"}],"version-history":[{"count":1,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/17771\/revisions"}],"predecessor-version":[{"id":17772,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/17771\/revisions\/17772"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/media\/17773"}],"wp:attachment":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<!-- This website is optimized by Airlift. Learn more: https://airlift.net. Template:. Learn more: https://airlift.net. Template: 69d9690a190636c2e0989534. Config Timestamp: 2026-04-10 21:18:02 UTC, Cached Timestamp: 2026-08-15 15:08:40 UTC -->