<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by DulithD on Medium]]></title>
        <description><![CDATA[Stories by DulithD on Medium]]></description>
        <link>https://medium.com/@dahanayakad22?source=rss-2381d64e18b1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*eHdt5hgTJyjrQMPova7kNQ.png</url>
            <title>Stories by DulithD on Medium</title>
            <link>https://medium.com/@dahanayakad22?source=rss-2381d64e18b1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 08:34:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dahanayakad22/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I Scraped Data from PDFs Using Python — The Clean Way]]></title>
            <link>https://python.plainenglish.io/how-i-scraped-data-from-pdfs-using-python-the-clean-way-802504a8e091?source=rss-2381d64e18b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/802504a8e091</guid>
            <category><![CDATA[scraping]]></category>
            <category><![CDATA[image-scanning]]></category>
            <category><![CDATA[pdf-scraping]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pdf]]></category>
            <dc:creator><![CDATA[DulithD]]></dc:creator>
            <pubDate>Wed, 22 Oct 2025 17:26:34 GMT</pubDate>
            <atom:updated>2025-10-27T09:33:42.316Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I Scraped Data from PDFs Using Python — The Clean Way</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p8-Yj4dA-bFcgLk9oWplzQ.jpeg" /></figure><p>If you’ve ever tried copying data from a PDF, you know the pain.<br>Text scattered everywhere, tables broken apart, random symbols — a nightmare for anyone who likes clean data.</p><p>A few months ago, I was building a data pipeline where hundreds of financial reports arrived <strong>only as PDFs</strong>. I had two choices:<br> 💀 spend days manually copying data<br> 💡 or automate it with Python.</p><p>So I did what any curious developer would do — I wrote a script.<br>Here’s how you can do it too — the right way.</p><p>🧩 Step 1: Meet the Libraries That Make It Possible</p><p>There are many PDF libraries in Python, but for <strong>data extraction</strong>, three stand out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*LpwQUU8yJ6iXqm03S3MVJA.png" /></figure><p>For this guide, let’s use <strong>pdfplumber</strong> — it’s lightweight, pure Python, and gives precise control.</p><p>⚙️ Step 2: Installation</p><pre>pip install pdfplumber pandas</pre><p>🧾 Step 3: Reading a PDF</p><p>Let’s open a sample PDF and see what we can get.</p><pre>import pdfplumber<br><br>with pdfplumber.open(&quot;sample.pdf&quot;) as pdf:<br>    first_page = pdf.pages[0]<br>    text = first_page.extract_text()<br>    print(text)</pre><p>Boom 💥 — instant text extraction.</p><p>📊 Step 4: Extracting Tables Like a Pro</p><p>Some PDFs contain structured tables — like invoices or bank statements.<br>Here’s how you can extract those with just a few lines:</p><pre>import pdfplumber<br>import pandas as pd<br><br>with pdfplumber.open(&quot;invoice.pdf&quot;) as pdf:<br>    page = pdf.pages[0]<br>    table = page.extract_table()<br><br>df = pd.DataFrame(table[1:], columns=table[0])<br>print(df)</pre><p>Clean, structured, ready for analysis or export.<br>You can even save it as CSV:</p><pre>df.to_csv(&quot;invoice_data.csv&quot;, index=False)</pre><h3>🚀 Step 5: Batch Process Multiple PDFs</h3><p>What if you have a folder full of PDFs?<br>Let’s loop through them automatically:</p><pre>import os<br>import pdfplumber<br>import pandas as pd<br><br>data = []<br><br>for file in os.listdir(&quot;pdfs&quot;):<br>    if file.endswith(&quot;.pdf&quot;):<br>        with pdfplumber.open(f&quot;pdfs/{file}&quot;) as pdf:<br>            page = pdf.pages[0]<br>            text = page.extract_text()<br>            row_data = {<br>                &quot;filename&quot;: file,<br>                &quot;text_content&quot;: text<br>            }<br>            data.append(row_data)<br><br>final_df = pd.DataFrame(data)<br>final_df.to_csv(&quot;all_data.csv&quot;, index=False)</pre><p>Now you’ve turned a messy PDF folder into a clean CSV dataset 🧹.</p><h3>🧠 Bonus Tip: When PDFs Refuse to Cooperate</h3><p>Not all PDFs are text-based — some are <strong>scanned images</strong>.<br>In that case, you’ll need <strong>OCR (Optical Character Recognition)</strong> using <strong>Tesseract</strong>:</p><pre>pip install pytesseract pillow<br>sudo apt install tesseract-ocr</pre><pre>from PIL import Image<br>import pytesseract<br><br>text = pytesseract.image_to_string(Image.open(&quot;scanned_page.png&quot;))<br>print(text)</pre><p>This trick makes your script unstoppable 💪.</p><h3>🏁 Final Thoughts</h3><p>With just a few lines of Python, we built a simple pdf scraper:</p><p>✅ Use <strong>pdfplumber</strong> for structured text and tables<br>✅ Use Batch Process scrape multiple pdf<br>✅ Use <strong>Tesseract OCR</strong> for scanned files</p><p>PDFs were never meant for structured data — they’re more like digital paper.<br>But with Python, libraries like <strong>pdfplumber</strong>, <strong>Camelot</strong>, and <strong>Tesseract</strong> can turn that chaos into usable insights.</p><p>If you love automation and clean data, this little project will make you feel like a magician.<br>And once you master it — you can apply the same logic to <strong>invoices</strong>, <strong>bank statements</strong>, <strong>research papers</strong>, or even <strong>government data</strong>.</p><p>Automate everything — don’t copy-paste ever again 🚀</p><h3>A message from our Founder</h3><p><strong>Hey, </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>Sunil</strong></a><strong> here.</strong> I wanted to take a moment to thank you for reading until the end and for being a part of this community.</p><p>Did you know that our team run these publications as a volunteer effort to over 3.5m monthly readers? <strong>We don’t receive any funding, we do this to support the community. ❤️</strong></p><p>If you want to show some love, please take a moment to <strong>follow me on </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>LinkedIn</strong></a><strong>, </strong><a href="https://tiktok.com/@messyfounder"><strong>TikTok</strong></a>, <a href="https://instagram.com/sunilsandhu"><strong>Instagram</strong></a>. You can also subscribe to our <a href="https://newsletter.plainenglish.io/"><strong>weekly newsletter</strong></a>.</p><p>And before you go, don’t forget to <strong>clap</strong> and <strong>follow</strong> the writer️!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=802504a8e091" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/how-i-scraped-data-from-pdfs-using-python-the-clean-way-802504a8e091">How I Scraped Data from PDFs Using Python — The Clean Way</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Practical Playwright + Python: A Beginner’s Guide to Reliable Web Scraping]]></title>
            <link>https://python.plainenglish.io/practical-playwright-python-a-beginners-guide-to-reliable-web-scraping-708ebd6917a3?source=rss-2381d64e18b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/708ebd6917a3</guid>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[playwrights]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[scraping]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[DulithD]]></dc:creator>
            <pubDate>Thu, 25 Sep 2025 17:00:37 GMT</pubDate>
            <atom:updated>2025-10-21T17:58:08.140Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CmIA-Zf8z_aSTi10paWU0A.png" /></figure><p>Playwright is a modern browser automation library that’s perfect for scraping JavaScript-heavy sites. This guide shows how to install Playwright, write simple scrapers (including pagination and infinite scroll), save results to CSV/SQLite, and follow best practices so your scrapers are reliable and respectful.</p><h3>Why Playwright for scraping?</h3><ul><li>Works with Chromium, Firefox, and WebKit (so you can run real browsers).</li><li>Handles JavaScript-heavy pages (unlike requests + BeautifulSoup).</li><li>Stable APIs, powerful “locator” model, and great debugging tools.</li><li>Runs headless for automation, headful for debugging.</li></ul><p>Use Playwright when the content is rendered client-side or when you need a real browser environment (clicks, JS execution, auth flows).</p><h3>Quick setup</h3><p>Open a terminal and run:</p><pre># 1) Install package<br>pip install playwright<br><br># 2) Install browser binaries (Chromium/Firefox/WebKit)<br>python -m playwright install</pre><p>If you prefer only Chromium (smaller download):<br> python -m playwright install chromium</p><p>First tiny script — “Hello Playwright”</p><pre># hello_playwright.py<br>from playwright.sync_api import sync_playwright<br><br>with sync_playwright() as p:<br>    browser = p.chromium.launch(headless=True)  # set headless=False to see the browser<br>    page = browser.new_page()<br>    page.goto(&quot;https://example.com&quot;)<br>    print(&quot;Title:&quot;, page.title())<br>    page.screenshot(path=&quot;example.png&quot;)<br>    browser.close()</pre><p>Run with python hello_playwright.py. You’ll get the page title and a screenshot — a good first smoke test.</p><h3>Core concepts (brief)</h3><ul><li><strong>Browser / Context / Page</strong>: Browser is the binary, context is like an incognito session (set user agent, headers, cookies there), page is a tab.</li><li><strong>Locators</strong>: page.locator(css) is a powerful way to find elements — avoids brittle selectors.</li><li><strong>Waiting</strong>: Use page.wait_for_selector() or page.wait_for_load_state() before extracting data.</li><li><strong>Headless vs headful</strong>: Use headful (headless=False) when debugging.</li></ul><h3>A practical example: Scrape quotes.toscrape.com with pagination</h3><p>This site is great for practicing. The script below demonstrates visiting pages, extracting structured data, and following the “Next” link.</p><pre># scrape_quotes_csv.py<br>from playwright.sync_api import sync_playwright<br>from urllib.parse import urljoin<br>import csv<br><br>START_URL = &quot;https://quotes.toscrape.com/&quot;<br><br>def scrape_quotes(start_url, out_csv=&quot;quotes.csv&quot;):<br>    rows = []<br>    with sync_playwright() as p:<br>        browser = p.chromium.launch(headless=True)<br>        context = browser.new_context()  # set user_agent or headers here if needed<br>        page = context.new_page()<br>        url = start_url<br><br>        while True:<br>            page.goto(url)<br>            page.wait_for_selector(&quot;.quote&quot;)  # wait until quotes appear<br><br>            quotes = page.locator(&quot;.quote&quot;)<br>            count = quotes.count()<br>            for i in range(count):<br>                q = quotes.nth(i)<br>                text = q.locator(&quot;.text&quot;).inner_text().strip()<br>                author = q.locator(&quot;.author&quot;).inner_text().strip()<br>                tags = q.locator(&quot;.tags a.tag&quot;).all_inner_texts()<br>                rows.append([text, author, &quot;, &quot;.join(tags)])<br><br>            # follow &quot;Next&quot; link if present<br>            next_link = page.locator(&quot;li.next a&quot;)<br>            if next_link.count() == 0:<br>                break<br>            href = next_link.nth(0).get_attribute(&quot;href&quot;)<br>            url = urljoin(start_url, href)<br><br>        browser.close()<br><br>    # save to CSV<br>    with open(out_csv, &quot;w&quot;, newline=&quot;&quot;, encoding=&quot;utf-8&quot;) as f:<br>        writer = csv.writer(f)<br>        writer.writerow([&quot;quote&quot;, &quot;author&quot;, &quot;tags&quot;])<br>        writer.writerows(rows)<br><br>if __name__ == &quot;__main__&quot;:<br>    scrape_quotes(START_URL)</pre><h3>Save to SQLite (optional)</h3><pre>import sqlite3<br><br>def save_to_sqlite(rows, db_path=&quot;quotes.db&quot;):<br>    conn = sqlite3.connect(db_path)<br>    c = conn.cursor()<br>    c.execute(&quot;&quot;&quot;<br>        CREATE TABLE IF NOT EXISTS quotes (<br>            quote TEXT,<br>            author TEXT,<br>            tags TEXT<br>        )<br>    &quot;&quot;&quot;)<br>    c.executemany(&quot;INSERT INTO quotes (quote, author, tags) VALUES (?, ?, ?)&quot;, rows)<br>    conn.commit()<br>    conn.close()</pre><h3>Dealing with JavaScript, AJAX, and infinite scroll</h3><p><strong>AJAX content:</strong> wait for the right selector or for a network response:</p><pre>page.goto(url)<br>page.wait_for_selector(&quot;.loaded-item&quot;)  # wait until JS injects items<br># or wait for a specific network response:<br>page.wait_for_response(lambda r: &quot;api/items&quot; in r.url and r.status == 200)</pre><p>Infinite scroll (basic):</p><pre>def infinite_scroll(page, pause_ms=1000, max_rounds=30):<br>    prev_height = page.evaluate(&quot;() =&gt; document.body.scrollHeight&quot;)<br>    for _ in range(max_rounds):<br>        page.evaluate(&quot;() =&gt; window.scrollTo(0, document.body.scrollHeight)&quot;)<br>        page.wait_for_timeout(pause_ms)  # milliseconds<br>        new_height = page.evaluate(&quot;() =&gt; document.body.scrollHeight&quot;)<br>        if new_height == prev_height:<br>            break<br>        prev_height = new_height</pre><p>Use infinite_scroll(page) before extracting elements.</p><h3>Useful options: user-agent, headers, and proxies</h3><p>Set a user agent or extra headers using a <strong>context</strong>:</p><pre>context = browser.new_context(<br>    user_agent=&quot;MyScraper/1.0 (+https://example.com)&quot;,<br>    extra_http_headers={&quot;Accept-Language&quot;: &quot;en-US,en;q=0.9&quot;}<br>)<br>page = context.new_page()</pre><p>Launch browser with a proxy:</p><pre>browser = p.chromium.launch(proxy={&quot;server&quot;: &quot;http://127.0.0.1:8000&quot;})</pre><h3>Best practices &amp; etiquette (must-read)</h3><ol><li><strong>Respect </strong><strong>robots.txt and the site’s terms of service.</strong> Use urllib.robotparser if unsure.</li><li><strong>Don’t hammer servers.</strong> Add delays: page.wait_for_timeout(500) or time.sleep() between pages.</li><li><strong>Use sensible request rates and randomize slightly</strong> so your behavior looks human-like.</li><li><strong>Rotate IPs / proxies responsibly</strong> if you’re hitting rate limits — but don’t try to evade explicit bans.</li><li><strong>Cache results</strong> and avoid re-downloading the same pages repeatedly.</li><li><strong>Store structured data</strong> (CSV/SQLite/Postgres) so you can resume and analyze later.</li><li><strong>Avoid scraping protected / paywalled data</strong> without permission.</li></ol><h3>Debugging tips</h3><ul><li>Run the browser <strong>headful</strong> (headless=False) and watch what happens.</li><li>page.screenshot(path=&quot;debug.png&quot;) and page.content() are lifesavers.</li><li>Use page.pause() to open the Playwright inspector and interactively test selectors.</li><li>If your selectors return nothing, try more robust locators (e.g., CSS classes + structure) or :text(&quot;...&quot;) helpers.</li></ul><h3>Common beginner mistakes (and how to avoid them)</h3><ul><li><strong>Forgetting to install browsers</strong> — run python -m playwright install.</li><li><strong>Not waiting for JS</strong> — always wait_for_selector after navigation.</li><li><strong>Using brittle selectors</strong> — prefer stable attributes and locator over fragile XPath built from indices.</li><li><strong>No error handling</strong> — wrap navigation/extraction in try/except, retry a few times.</li></ul><h3>When to pick alternatives</h3><ul><li>For <strong>simple static</strong> pages, requests + BeautifulSoup is faster and lighter.</li><li>For extremely heavy scraping at scale, consider APIs (if available) or purpose-built scraping platforms.</li></ul><h3>Final Thoughts</h3><p>With just a few lines of Python, we built a simple playwright scraper that:</p><ul><li>Installation steps ✅</li><li>A tiny “hello” script ✅</li><li>A full pagination example that saves to CSV ✅</li><li>Infinite scroll &amp; AJAX handling tips ✅</li><li>Best practices and debugging tips ✅</li></ul><h3>A message from our Founder</h3><p><strong>Hey, </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>Sunil</strong></a><strong> here.</strong> I wanted to take a moment to thank you for reading until the end and for being a part of this community.</p><p>Did you know that our team run these publications as a volunteer effort to over 3.5m monthly readers? <strong>We don’t receive any funding, we do this to support the community. ❤️</strong></p><p>If you want to show some love, please take a moment to <strong>follow me on </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>LinkedIn</strong></a><strong>, </strong><a href="https://tiktok.com/@messyfounder"><strong>TikTok</strong></a>, <a href="https://instagram.com/sunilsandhu"><strong>Instagram</strong></a>. You can also subscribe to our <a href="https://newsletter.plainenglish.io/"><strong>weekly newsletter</strong></a>.</p><p>And before you go, don’t forget to <strong>clap</strong> and <strong>follow</strong> the writer️!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=708ebd6917a3" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/practical-playwright-python-a-beginners-guide-to-reliable-web-scraping-708ebd6917a3">Practical Playwright + Python: A Beginner’s Guide to Reliable Web Scraping</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Beginner-Friendly Guide to Web Crawling with Python, Requests, and BeautifulSoup]]></title>
            <link>https://medium.com/@dahanayakad22/a-beginner-friendly-guide-to-web-crawling-with-python-requests-and-beautifulsoup-e59e840961a6?source=rss-2381d64e18b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e59e840961a6</guid>
            <category><![CDATA[web-crawler]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[web-crawling]]></category>
            <category><![CDATA[crawling]]></category>
            <category><![CDATA[scraping]]></category>
            <dc:creator><![CDATA[DulithD]]></dc:creator>
            <pubDate>Sun, 07 Sep 2025 16:12:02 GMT</pubDate>
            <atom:updated>2025-09-07T16:12:02.853Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TVzwWh5RV-MTVtUxc2c7-g.png" /></figure><p>Have you ever wanted to grab information from a website and turn it into data you can use? Maybe a list of book titles, job postings, or the latest news headlines? That’s where <strong>web crawling</strong> comes in.</p><p>In this article, we’ll explore how to crawl web pages using two of the most popular Python libraries: <strong>Requests</strong> (to fetch web pages) and <strong>BeautifulSoup</strong> (to parse HTML and extract data).</p><p>Don’t worry — this won’t be boring or overly technical. By the end, you’ll be able to write your own simple crawler.</p><h3>What is Web Crawling?</h3><p>Web crawling is the process of <strong>automatically navigating through web pages and extracting information</strong>. Think of it as teaching Python to be a mini search engine bot that reads websites for you.</p><p>For example, instead of manually copying the titles of 50 blog posts, you can write a crawler that does it in seconds.</p><h3>Tools We’ll Use</h3><ul><li><strong>Requests</strong> → To download the HTML of a web page.</li><li><strong>BeautifulSoup</strong> → To parse and extract meaningful data from that HTML.</li></ul><p>Install them first:</p><pre>pip install requests beautifulsoup4</pre><h3>Step 1: Fetch a Web Page with Requests</h3><p>Let’s say we want to crawl quotes from <a href="http://quotes.toscrape.com/">http://quotes.toscrape.com</a></p><pre>import requests<br><br>url = &quot;http://quotes.toscrape.com&quot;<br>response = requests.get(url)<br><br>print(response.status_code)  # 200 means success<br>print(response.text[:500])   # Print first 500 characters of HTML</pre><p>👉 At this stage, we’re just <strong>grabbing the HTML code</strong> of the page.</p><h3>Step 2: Parse HTML with BeautifulSoup</h3><p>The HTML looks messy. Let’s use BeautifulSoup to make it structured.</p><pre>from bs4 import BeautifulSoup<br><br>soup = BeautifulSoup(response.text, &quot;html.parser&quot;)<br><br># Extract all quote blocks<br>quotes = soup.find_all(&quot;span&quot;, class_=&quot;text&quot;)<br><br>for q in quotes:<br>    print(q.get_text())</pre><p>Output:</p><pre>“The world as we have created it is a process of our thinking...”<br>“It is our choices, Harry, that show what we truly are...”<br>...</pre><p>🎉 Nice! We’ve just extracted clean text from the website.</p><h3>Step 3: Crawling Multiple Pages</h3><p>Most websites have <strong>multiple pages</strong>. For example, our quotes site has “Next” buttons.</p><p>We can loop through them:</p><pre>page = 1<br>while True:<br>    url = f&quot;http://quotes.toscrape.com/page/{page}/&quot;<br>    response = requests.get(url)<br>    <br>    if &quot;No quotes found!&quot; in response.text:<br>        break  # stop if page doesn’t exist<br>    <br>    soup = BeautifulSoup(response.text, &quot;html.parser&quot;)<br>    quotes = soup.find_all(&quot;span&quot;, class_=&quot;text&quot;)<br>    <br>    for q in quotes:<br>        print(q.get_text())<br>    <br>    page += 1</pre><p>Now, Python crawls <strong>all pages automatically</strong>.</p><h3>Step 4: Extract Authors and Tags</h3><p>We can also extract extra details:</p><pre>for quote in soup.find_all(&quot;div&quot;, class_=&quot;quote&quot;):<br>    text = quote.find(&quot;span&quot;, class_=&quot;text&quot;).get_text()<br>    author = quote.find(&quot;small&quot;, class_=&quot;author&quot;).get_text()<br>    tags = [tag.get_text() for tag in quote.find_all(&quot;a&quot;, class_=&quot;tag&quot;)]<br>    <br>    print(f&quot;Quote: {text}\nAuthor: {author}\nTags: {tags}\n&quot;)</pre><p>Output (sample):</p><pre>Quote: “The world as we have created it is a process of our thinking...”<br>Author: Albert Einstein<br>Tags: [&#39;change&#39;, &#39;deep-thoughts&#39;, &#39;thinking&#39;, &#39;world&#39;]</pre><p>Now we’re not just collecting text — we’re <strong>structuring data</strong> like a mini-database.</p><h3>Step 5: Save Data to CSV</h3><p>Why not save our results for later use?</p><pre>import csv<br><br>with open(&quot;quotes.csv&quot;, &quot;w&quot;, newline=&quot;&quot;, encoding=&quot;utf-8&quot;) as f:<br>    writer = csv.writer(f)<br>    writer.writerow([&quot;Quote&quot;, &quot;Author&quot;, &quot;Tags&quot;])<br>    <br>    for quote in soup.find_all(&quot;div&quot;, class_=&quot;quote&quot;):<br>        text = quote.find(&quot;span&quot;, class_=&quot;text&quot;).get_text()<br>        author = quote.find(&quot;small&quot;, class_=&quot;author&quot;).get_text()<br>        tags = &quot;, &quot;.join(tag.get_text() for tag in quote.find_all(&quot;a&quot;, class_=&quot;tag&quot;))<br>        <br>        writer.writerow([text, author, tags])</pre><p>After running this, check your folder — you’ll find a quotes.csv file with all the data neatly stored.</p><h3>Best Practices (Read Before You Crawl)</h3><ol><li><strong>Check the site’s robots.txt</strong> → Some sites don’t allow crawling. Example: <a href="https://example.com/robots.txt.">https://example.com/robots.txt.</a></li><li><strong>Don’t overload servers</strong> → Add small delays (time.sleep(1)) between requests.</li><li><strong>Use crawling responsibly</strong> → Don’t scrape sensitive or copyrighted data.</li></ol><h3>Final Thoughts</h3><p>With just a few lines of Python, we built a simple crawler that:</p><ul><li>Fetches pages with Requests</li><li>Parses content with BeautifulSoup</li><li>Loops through multiple pages</li><li>Extracts quotes, authors, and tags</li><li>Saves everything into a CSV file</li></ul><p>This is only the beginning — you can expand this into projects like:</p><ul><li>Collecting job listings</li><li>Extracting book details</li><li>Building a dataset for machine learning</li></ul><p>The best way to get good at crawling is <strong>practice</strong>. Pick a site (preferably simple and legal to scrape), and try building your own crawler.</p><p>Happy Crawling 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e59e840961a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>