<?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 rootertwo on Medium]]></title>
        <description><![CDATA[Stories by rootertwo on Medium]]></description>
        <link>https://medium.com/@alfianabd23?source=rss-4fe947d08d10------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*D_w99PH-j8hDIXlMTIRwcg.jpeg</url>
            <title>Stories by rootertwo on Medium</title>
            <link>https://medium.com/@alfianabd23?source=rss-4fe947d08d10------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 06:34:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alfianabd23/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[“Python Cracking The Code: Scraping IKEA Product for Depth Market Research and Analysis”]]></title>
            <link>https://medium.com/@alfianabd23/python-cracking-the-code-scraping-ikea-product-for-depth-market-research-and-analysis-1ec7fb5d4bc3?source=rss-4fe947d08d10------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ec7fb5d4bc3</guid>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[data-analyst]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[marketing-strategies]]></category>
            <category><![CDATA[selenium]]></category>
            <dc:creator><![CDATA[rootertwo]]></dc:creator>
            <pubDate>Fri, 08 Dec 2023 09:35:38 GMT</pubDate>
            <atom:updated>2023-12-08T12:23:29.755Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FftEc7tTViWE-SkedVTeBg.png" /><figcaption>Image By Author</figcaption></figure><h4>Understanding the Market for Starting A New Business</h4><p>Before building a business, a deep understanding of market trends and consumer behavior is the initial key to success in the digitalization era. Customer preferences and viewpoints can provide a very significant competitive advantage, so the business runs stably.</p><p>I tried to bring the concept by utilizing programming languages<em> and </em>show you a workflow using Python and Web Scraping Techniques to obtain specific information regarding product details on the IKEA websites.</p><p>Is not about programming. But, as a key to opening the secret of market data. This article combines the power of Python with a huge potential for applying the technology for market research and in-depth analysis, making it a valuable guide for those, who are looking to optimize business strategy through detailed data insights.</p><h4>Combination Python with Visual Studio Code (VSC)</h4><p>Python is a programming language suitable for beginners and easy to understand by offering various libraries and frameworks. The VSC extension has large resources and an active community.</p><p>Considering that Visual Studio Code can also be used on all OS (windows, linux, and macOS), this combination was the right choice for me to carry out the web scraping technique this time.</p><p>Both combinations, increase development functionality for various purposes, including Web Scraping, Data Analysis, and so on.</p><h4>Next, Why Scraping?</h4><p>Let’s say. I want to get information about each product, as follows:</p><ul><li>Product Name, Url’s, Price, Sold, Description, Product Code.</li></ul><p>This information is used as a key in market comparisons between e-commerce service providers. To get detailed information on each product, <strong><em>web scraping</em></strong> is a powerful tool for exploring automating getting detailed products, and visualizing data easily.</p><p><strong>Note:</strong></p><blockquote><strong>It’s important to remember</strong>, while web scraping can be a powerful tool for capturing data, there are some challenges. One of the common challenges is handling complex website structures or frequent changes to page layouts.</blockquote><blockquote>During the scraping process, several obstacles by web policies can hinder or restrict access. However, these challenges do not become obstacles during the scraping process. In dealing with complex web, trial and error can add new insights into writing reliable code.</blockquote><h4>Web Scraping Methode (Step By Step)</h4><p>Before creating a custom function you have to install BeautifulSoup, Pandas, and Selenium on your venv(virtual environment), import the selenium module, and import time.</p><ul><li>pip install selenium</li><li>pip install beautifulsoup4</li><li>pip install pandas</li><li>pip install openpyxl</li></ul><p><strong>Note:</strong></p><blockquote><em>If you are a user of macOS or linux, you can run using </em><strong><em>pip3</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*ymPC74ZLEr-2rq0ocGOZuQ.png" /><figcaption>Image by Author (path: chrome://settings/help)</figcaption></figure><p>Check your Chromedriver version as shown in the picture above, add a webdriver to your project and then install (your chromedriver version).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/168/1*qKirqG5MuGQyjISAO2aqYg.png" /><figcaption>Example</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddea72fa77e1461bd79ec8fc2e4fa147/href">https://medium.com/media/ddea72fa77e1461bd79ec8fc2e4fa147/href</a></iframe><p>The code above is the initial stage, by importing several modules to support the scraping and data analysis process. Like using selenium moduleslike webdriver, to control and access web pages.</p><p>Next, chrome options can be configured by importing the options, WebDriverWaitand expected_conditions class from the selenium.webdriver.support.ui module, which is used to carry out handling before carrying out the scrapping process.</p><p>selenium.webdriver.common.by import Byhelp search for web pages, and TimeoutException to handle timeout situations in selenium operations. Imported <em>BeautifulSoup</em> to parse the HTML code on a Web page. Pandas to manipulate, analyze data, and save the parsing results in Excel files later.</p><p>Finally, use the time module to handle execution time, using time.sleep(). this combination will perform web scraping reliably.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*29tKm0ruXZLjL3essG_w3Q.png" /><figcaption>Inspect Html Element</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4dae882af9560173b56228bdbcaa18b2/href">https://medium.com/media/4dae882af9560173b56228bdbcaa18b2/href</a></iframe><p>The first step is collecting_link_productsURLs from a web page. The function utilizes Selenium and BeautifulSoup modules, WebDriver to open the web page, and BeautifulSoup is used to search for all elements with the &lt;div&gt; tag and the class attribute &quot;d-flex flex-row&quot; which contains product name information. A similar pattern is applied to product name searches get_page.find_all to get all product names on the IKEA site.</p><p>Next, the function iterates through these elements and stores them in the product_urlslist. This function provides flexibility in the parsing process and &lt;collect_link_products is considered an effective first step to obtaining product information.</p><p>Parsing results are stored in the form of a product_urls dictionary and returned using the return statement. The function helps in collecting product URLs from IKEA web pages for use in subsequent steps in the scraping process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*cXMJbwt08VwGhMXh0xv0vQ.png" /><figcaption>Inspect Element Data Price</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06836f94a676e161b9d8f1737b7d0074/href">https://medium.com/media/06836f94a676e161b9d8f1737b7d0074/href</a></iframe><p>In custom function 2, I retrieve information related to product prices from a web page, using BeautifulSoup and looking for elements that describe data_price.</p><p>Right-click on the mouse and inspect, the element is located in the &lt;span&gt; tag. I use an if, else Statement, to describe, if the product price is available then return, and return the function None to indicate that the product price is not available.</p><p>Use the product_price function as one data which will be combined with several other functions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b84b3ac004dc5106aeb1ca3e732ae16/href">https://medium.com/media/4b84b3ac004dc5106aeb1ca3e732ae16/href</a></iframe><p>That Custom function is used to search elements and classes that have been adjusted. If the element is found, the newline character (&quot;\n&quot;) will be removed using a return element.text.replace<em> </em>if statement and the else statement if the element is not found with return None.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*NgT0qywhWXKHw8rQLN7PPw.png" /><figcaption>Tag Element for Sold</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*cJ37Y_EhYpHwYqYfEhJ5ow.png" /><figcaption>Tag Element for Description</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*sYR6C--_QwSFHSY2M2T4qw.png" /><figcaption>Tag Element for Product Code</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/319beac223b6e5f14bd370e62660e3ef/href">https://medium.com/media/319beac223b6e5f14bd370e62660e3ef/href</a></iframe><p>This function has an important role in extracting specific information results from parsing web pages using BeautifulSoup. This code will produce scraping output in dictionary form and will saved in Excel Formatted.</p><p>The information, successfully stored involves several items Product Name , Urls, Price, Sold, Description, Product Code. Each item is called using a parsing function with adjusted parameters, so the data can be used to produce the expected output.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da797932eec4181ac8c8c2a015895da3/href">https://medium.com/media/da797932eec4181ac8c8c2a015895da3/href</a></iframe><p>For opening and accessing web pages using Selenium Webdriver. This function overcomes possible delays in page loading by waiting until a certain element appears in the try and excepthandling.</p><p>If the page is successfully loaded within the specified period (two seconds), the HTML page will be taken and converted into an BeautifulSoup object. These objects are returned for use in further information extraction stages, as occurs in subsequent steps in the web scraping process.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5496426788d5f103dfe6bd6655df8369/href">https://medium.com/media/5496426788d5f103dfe6bd6655df8369/href</a></iframe><p>The main function, I designed to automate the process of retrieving product data from the IKEA Website using Selenium Webdriver with Chrome.</p><p>Start by setting various options for the ChromeDriver, including running in headless mode (no graphical interface), enabling Javascript, reducing redundant logs, and ignoring SSL certificate errors, to optimize the scraping process.</p><p>Then enters a loop, it will be sequentially accessing product catalog pages. For each page, the script collects individual product URLs using the collect_link_products function. If no product URL is found (==0), indicating the last page of the catalog, and looping process stops.</p><p>Otherwise, the script navigates to the product page and tries to retrieve data using the access_page_selenium scraping functions. If successful, the scraped data will be added to the final_result list.</p><p>This script includes error handling to manage exceptions during the scraping process. After processing all the products on a page, this script will wait for 15 seconds before continuing to the next page.</p><p>To avoid server-side bots or overloading the website server and will continue to the next page. Next, this script will continue the process until all catalog pages have been processed, and compile the scraped data into a more comprehensive or structured collection.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae3a51f4c6313b7b6754437ba1812379/href">https://medium.com/media/ae3a51f4c6313b7b6754437ba1812379/href</a></iframe><p>The final part of the Python script is successfully scraped data collected in the final_result<em> </em>list and converted into pandas DataFrame, which is a common table data structure in Python, used for data analysis.</p><p>This DataFrameDataFrame will be saved into an Excel file, I created it with the name &quot;projectscraping.xlsx&quot;. During this saving process, the DataFrame index is not included in the Excel file, which makes the output cleaner and focused on the actual data.</p><p>After data saving is completed, the script shows &quot;time duration&quot;to carry out the scraping process and complete execution. I use this to find out how long the duration &quot;start_time-end_time&quot;is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*A4uq-mZRAls7_uxLQuf9Eg.png" /><figcaption>Scraping Duration</figcaption></figure><p>The scraping result duration will be shown in the console &quot;VSC&quot;. This is useful for monitoring the efficiency and performance of the scraping script that has been created, providing insight into how long the script takes to run from start to finish. The next step is saving the file using Pandas.</p><p><strong>Result</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LYWC_iwOap7ewkigh2ms5Q.png" /><figcaption>Sample Result</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*irBjawNSV-YDtLL1wWgidw.png" /><figcaption>Sample Result</figcaption></figure><p>Through &quot;web scraping techniqueson the IKEA website, we can collect various information that is very valuable for analysis and research automatically. The following are the specific types of data that I got as shown in the image above:</p><ul><li>&quot;Product Name&quot;: Information about the names of IKEA products involving various types</li><li>&quot;Urls&quot;: Product URLs provide direct access to pages specific to each item on the IKEA site. This can be used to refer back to or share product information easily.</li><li>&quot;Price&quot;: Product price data provides an understanding of the price range for each item. This can help you compare prices and make decisions.</li><li>&quot;Sold&quot;: The number of units of a product, that have been sold indicates the product’s popularity and demand among consumers.</li><li>&quot;Description&quot;: This point will help potential buyers to make more informed decisions.</li><li>&quot;Product Code&quot;: IKEA’s unique product code can be used as a unique identification for each item. This is useful in tracking and grouping products systematically.</li></ul><p><strong>Conclusion</strong></p><p>In-depth market research using web scraping techniquesone of the IKEA sites as an example. Provides significant strategic advantages for entrepreneurs who want to start a business or need to research.</p><p>With data that has been shown to include accurate information such as Product Name, Price, Sold, Description, and Product Code it can be used to better understand market trends and consumer behavior.</p><p>Benefits include a better understanding of consumer preferences, price and competitiveness analysis, product popularity evaluation, comparison with competitors, product portfolio optimization, informed decision-making, and identification of new market opportunities.</p><p>With this insight, you can design more effective business strategies, develop products that better suit market needs, and win the competition in a competitive market.</p><blockquote>By utilizing market through web scraping technology, you gain in-depth insight into the importance of research and analysis before making a decision. Let’s innovate by utilizing web scraping technology to make it easier visualize data. Happy learning guys………😉</blockquote><p><strong><em>reference:</em></strong></p><p><a href="https://www.selenium.dev/documentation/">https://www.selenium.dev/documentation/</a></p><p><a href="https://chromedriver.chromium.org/">https://chromedriver.chromium.org/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ec7fb5d4bc3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Website Scraping Techniques Using Python: Extracting Movie Script for Film Enthusiast]]></title>
            <link>https://medium.com/@alfianabd23/website-scraping-techniques-using-python-extracting-movie-script-for-film-enthusiast-c56ff2e64bdf?source=rss-4fe947d08d10------2</link>
            <guid isPermaLink="false">https://medium.com/p/c56ff2e64bdf</guid>
            <category><![CDATA[data-extraction]]></category>
            <category><![CDATA[scraping-with-python]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[data-mining]]></category>
            <category><![CDATA[web-scraping]]></category>
            <dc:creator><![CDATA[rootertwo]]></dc:creator>
            <pubDate>Sun, 19 Nov 2023 05:54:20 GMT</pubDate>
            <atom:updated>2023-11-19T05:54:20.419Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*xMd1AofZrvC5EYnhGWDTfQ.png" /><figcaption><a href="https://www.promptcloud.com/wp-content/uploads/2023/03/Creative-Business-24-850x450.png">https://www.promptcloud.com/wp-content/uploads/2023/03/Creative-Business-24-850x450.png</a></figcaption></figure><p><strong>Links</strong>: <a href="https://subslikescript.com/movies">https://subslikescript.com/movies</a></p><p><strong>GitHub Code</strong>: <a href="https://github.com/Alfian-IDN/Web-Scraping">https://github.com/Alfian-IDN/Web-Scraping</a></p><h3><strong>Intro :</strong></h3><p>Web scraping is a technique for extracting data from websites to collect information on both small and large scales. Converting web-formatted data into organized structures like databases or spreadsheets enables seamless analysis for various purposes such as academic research, market insights, and data mining.</p><h4><strong>The main objective of my script</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*gUpJSyQYHyCu3N09QeAoaQ.png" /><figcaption>script function</figcaption></figure><p>The function <strong><em>scrape_and_save_transcript</em></strong> automates the retrieval and storage of movie scripts from a specified website. It accesses HTML content using the requests library, parses it with <em>BeautifulSoup</em>, and extracts movie titles and scripts. Forbidden characters in file names are removed using a <strong><em>regex(Regular Expression) </em></strong>pattern. The main function orchestrates the process, forming URLs dynamically, making requests, and systematically storing results in a folder. It iterates through pages 1 to 5, printing URLs for progress monitoring. The script identifies ‘article’ elements, extracts movie links, and invokes scrape_and_save_transcript for each link. The script includes a conditional check for standalone functionality.</p><p><strong>Technologies Used</strong>:</p><p>In Developing this script, I utilized:</p><ol><li><strong>Python Programming Language</strong>: Known for its clear syntax and data-handling libraries.</li><li><strong>BeautifulSoup</strong>: Used for parsing HTML and XML, simplifying document navigation.</li><li><strong>requests</strong>: Streamline HTTP requests in Python, known for its ease of use.</li></ol><p>This combination enhances the effectiveness of the web scraping process. you need to install several packages in your virtual environment (<strong><em>venv</em></strong>).</p><ul><li><strong><em>pip install requests</em></strong></li><li><strong><em>pip install BeautifulSoup4</em></strong></li><li><strong><em>pip install lxml</em></strong></li></ul><h3><strong><em>Script Logic for Movie Transcript Extraction and Storage</em></strong></h3><p>In this script, the focus is on extracting and storing movie transcripts from the website<a href="https://subslikescript.com/"><strong><em> https://subslikescript.com</em></strong></a>. The main features can be summarized as follows.</p><ol><li><strong>Automated Collection of Movie Transcripts -&gt; </strong><em>Objective</em>: Gather movie transcripts from the specified website and save them as text files.</li><li><strong>Navigation Across Multiple Pages -&gt; </strong>Procedure: The script systematically gathers movie transcripts from the first five pages of the website dedicated to listing them, successfully extracting content from each page.</li><li><strong>Extraction of Individual Movie Links -&gt;</strong> Approach: The script prepares links to individual movie transcripts on these pages, setting the stage for subsequent scraping processes.</li><li><strong>Saving Each Transcript -&gt; </strong>Process: During each movie page visit, the script extracts the title, cleans it for a valid filename, and then saves the complete transcript in a text file named after the movie</li><li><strong>Organization of Saved Transcripts -&gt; </strong>Structuring: Text files are organized in the “multiple-pages” folder, ensuring a systematic and easily retrievable structure for the scraped data.</li></ol><h3><strong>Website Selection and Data Structure Explanation</strong></h3><p>I selected <a href="https://subslikescript.com/">https://subslikescript.com</a> for its extensive collection and structured presentation of movie transcripts, making it ideal for automated scraping.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*0U0SNTrTrdzeU0S9dzJLhg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*UH9349Qnsc_4CwQSJfk2nQ.png" /><figcaption><strong>Data Structured Image</strong></figcaption></figure><p><strong>Understanding the Site’s Data Structure:</strong></p><ul><li>The main movie transcripts are closed within an <em>article tag</em>, with the <strong><em>class= “main-article”</em></strong>.</li><li>Links to individual movie transcript pages are found on the main listing pages.</li><li>The typical structure of each movie page includes <em>a </em><strong><em>title</em> </strong>in an <strong><em>h1</em> tag </strong>and a dedicated container (div with a specific class) for the transcript text.</li></ul><p>The script efficiently navigates, extracts, and stores content by leveraging the structured setup of the website. Python’s <strong><em>BeautifulSoup</em></strong> and <strong>requests</strong> libraries simplify HTML parsing and HTTP requests, while regular expressions clean titles for system-file compatibility, especially when handling special characters.</p><h3>Exploring Main Components</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*SjLUdbGyyX9nKSX5kbGAcw.png" /></figure><p>This script describes several key components to perform tasks:</p><ol><li><strong>Requests:</strong> This library is used to send HTTP requests to the website. It enables the script to access and download the necessary web page content for the scraping process.</li><li><strong>BeautifulSoup</strong>: Used to parse the HTML. It’s easier to find and access various elements of the web page, such as the text of the movie transcripts, links, titles, etc.</li><li><strong>re</strong>: the library (<strong><em>Regular Expression</em></strong>) is utilized. This involves removing invalid characters from the movie titles, specifically in file names. Ensuring the correctness of filenames when storing transcripts is crucial to avoid potential errors.</li><li><strong>os</strong>: The library is utilized for interacting with your computer’s file system. <strong>os</strong> assists in creating file paths for storing the scraped transcripts and ensures that the files are saved in the correct location.</li></ol><p>These components play a vital role in effectively and executing the scraping tasks, from accessing data on the web.</p><h3><strong>Writing the Scraping Function</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*mfsfUMCPQIDLL2ZvFcCvDQ.png" /></figure><p>Function scrape_and_save_transcript:</p><ul><li><strong>Fetching Page Content with requests.get</strong>: I start this function by sending an HTTP request to the URL using requests.get. This serves to access the web page content that I intend to scrape.</li><li><strong>Parsing HTML with BeautifulSoup</strong>: After downloading the page content, I utilize BeautifulSoup to parse the HTML. This allows me to navigate and extract data from the web page’s HTML structure.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*kxdPnTyvyQoC_6YxYEoWXg.png" /><figcaption><strong>Regex to clean the Title</strong></figcaption></figure><ul><li><strong>Using Regex to Clean the Title</strong>: I use a regular expression (<strong><em>regex</em></strong>) and define it in the pattern variable, as some movie titles contain special characters. This step is important to clean unwanted characters from the movie titles, ensuring that they are safe to use as filenames.</li><li><strong>Saving the Transcript to a File</strong>: Next, I extract the movie transcript text within a div with the class full-script. This transcript is then saved into a text file, where the filename is derived from the cleaned movie title. The file storage location is predetermined using <em>folder_path</em> (named <em>multiple-pages</em>), and all file operations are conducted using the os library.</li></ul><p>I efficiently employ this function to collect, process, and store movie transcripts.</p><h3>Implementing the Main Control Function</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*tfKV-_PP0Hf5cK9FBhDkjQ.png" /><figcaption><strong>Control Function</strong></figcaption></figure><p>I designed the main function in this script as the primary controller for the overall scraping process. Let’s discuss how I carry out scraping to access multiple pages and collect as well as iterate over the links:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*IJbbpA7IYjL8l0iXm9b3tg.png" /></figure><ul><li><strong>Setting the Main URL</strong>: I start this function by defining the base URL of the website (<em>https://subslikescript.com</em>). This URL serves as the foundation for navigating through various pages of the site.</li><li><strong>Iterating Through Pages</strong>: The function uses a for loop to iterate through the first five pages of the movie transcripts section on the website. I construct the URL for each page by appending the page number to the base URL (<strong>url = f’{root}/movies/?page={page}</strong>’). This loop allows the script to systematically access multiple pages, thereby expanding the scope of scraping.</li><li><strong>Fetching Page Content</strong>: For each page URL, the script sends an HTTP GET request using <em>requests.get(url)</em>. The response text, which is the HTML content of the page, is stored in content.</li><li><strong>Parsing HTML Content</strong>: The HTML content is then parsed using BeautifulSoup, creating a soup object. This object is used for navigating the HTML structure of the web page to access the predefined data.</li><li><strong>Collecting Movie Transcript Links</strong>: The function then locates the main article section <strong>(<em>‘article’, class_=’main-article’</em>)</strong> where the individual movie links are listed. I extract all the href attributes from the <strong><em>a</em></strong> tags within this section, forming a list of links to individual movie transcript pages <strong>(<em>links = [f’{root}/{link[“href”]}’ for link in box.find_all(‘a’, href=True)</em>])</strong>.</li><li><strong>Iterating Over Collected Links</strong>: For each link in the compiled list, the script prints the URL (for debugging or logging purposes) and then calls the <strong><em>scrape_and_save_transcript function</em></strong>. This function is responsible for scraping the transcript from each individual movie page and saving it as a text file.</li><li><strong>Organizing the Saved Transcripts</strong>: All the scraped transcripts are stored in a folder named ‘<strong><em>multiple-pages</em></strong><em>’</em>, ensuring that the data is not only collected but also organized in a structured one place.</li></ul><p>In summary, the main function systematically navigates through multiple pages of the website, collects links to individual movie transcripts, and utilizes the scrape_and_save_transcript function to extract and save each transcript, thus automating and organizing the entire process.</p><p><strong>Running The Script</strong></p><p>In this section, I want to show you how the program runs:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2Fc1e38a35d2284eb78bfe73fe1776bfed&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2Fc1e38a35d2284eb78bfe73fe1776bfed&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2Fc1e38a35d2284eb78bfe73fe1776bfed-00001.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1280" height="960" frameborder="0" scrolling="no"><a href="https://medium.com/media/2153e706a551d57c6f930d19660058f5/href">https://medium.com/media/2153e706a551d57c6f930d19660058f5/href</a></iframe><p><strong>Storage of Movie Transcripts</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*DjhGZADIXNR8ejnYqSkKKw.png" /><figcaption><strong>Multiple-Pages Folder</strong></figcaption></figure><p>The movie transcript text files are stored in a designated folder named <em>“multiple-pages”</em>. This systematic approach ensures the organized storage of the scraped data in one easily accessible location. This method allows convenient access to the compiled movie transcript results, each neatly stored under its respective movie title within the <em>“multiple-pages” </em>directory. This automated organization not only ensures accessibility but also serves as a foundation for future analytical efforts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*V_QJ9KWJlBjkz_HmHg-4zA.png" /><figcaption><strong>Special Character</strong></figcaption></figure><p>Each movie transcript text file is named after the movie title. To ensure compatibility with the file system, I refine the titles by removing special or invalid characters using the regex function. For example, if a movie title contains characters like exclamation marks or question marks, those specific characters are excluded.</p><h3><strong>Handling Common Issues</strong></h3><p>In the “<em>Handling Common Issues</em>” stage, we address typical challenges in web scraping, including <strong><em>HTTP errors (e.g., 403 or 404)</em></strong>, <strong><em>absent elements</em></strong>, and <strong><em>encoding problems</em></strong>. To resolve HTTP errors, validate the URL, check HTTP headers, and use tools like “requests” for retries. For absent elements, reassess the HTML structure and implement error-handling techniques. Address encoding challenges by confirming correct encoding and using tools like “<strong>BeautifulSoup</strong>” to handle invalid characters. Troubleshooting tips include regularly checking error logs, maintaining source data backups, and updating scraping programs for website changes. Understanding and applying these strategies ensure a smoother web scraping experience.</p><h3><strong>Conclusion</strong></h3><p>The script I’ve developed effectively fulfills its primary role by automating the process of collecting movie scripts from a website. Employing web scraping techniques, the script successfully accomplishes its predefined objectives, including:</p><ul><li>Efficient navigation through web pages.</li><li>Recognition of script text on each page by extracting titles.</li><li>Preservation of content in the form of text files.</li></ul><p>This proves highly advantageous for movie enthusiasts or content analysts, eliminating the need for manual text copying.</p><p>By following the outlined web scraping techniques, you can create similar tools to access and gather data from diverse websites. Experiment and adapt this script to suit your unique projects. <strong>Happy exploring</strong>!</p><p><em>Have you tested this web scraping script? Share your experiences or pose questions in the comments section below the article. I’m here to provide answers and engage in discussions with you. Furthermore, if you’ve found value in this article and wish to receive ongoing content on web scraping, the Python programming language, or related topics, consider following me on Medium. By following this step, you will receive the most recent content directly in your feed. </em><strong><em>Keep exploring and experimenting with the web scraping script, diving further into exploration! Thanks</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c56ff2e64bdf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>