<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Data Science - Software Developer's Tour</title>
	<atom:link href="https://pawelmajewski.com/category/programming/data-science/feed/" rel="self" type="application/rss+xml" />
	<link>https://pawelmajewski.com</link>
	<description>Website about programming, news in IT and more</description>
	<lastBuildDate>Sun, 29 Jun 2025 22:30:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.2</generator>

<image>
	<url>https://pawelmajewski.com/wp-content/uploads/2024/02/logo_normal.png</url>
	<title>Data Science - Software Developer's Tour</title>
	<link>https://pawelmajewski.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Understanding K-Nearest-Neighbors (KNN) &#8211; Essential Machine Learning Algorithm</title>
		<link>https://pawelmajewski.com/understanding-k-nearest-neighbors-knn-essential-machine-learning-algorithm/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=understanding-k-nearest-neighbors-knn-essential-machine-learning-algorithm</link>
					<comments>https://pawelmajewski.com/understanding-k-nearest-neighbors-knn-essential-machine-learning-algorithm/#respond</comments>
		
		<dc:creator><![CDATA[Paweł Majewski]]></dc:creator>
		<pubDate>Sun, 29 Jun 2025 01:21:34 +0000</pubDate>
				<category><![CDATA[Data Science]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[Machine learning]]></category>
		<category><![CDATA[Science of Data]]></category>
		<guid isPermaLink="false">https://pawelmajewski.com/?p=8875</guid>

					<description><![CDATA[<p>A quick introduction to this algorithm KNN is used to determine the class of our sample data. To understand this more clearly, please take a look at the plot below. We have two groups of samples: blue ones and red ones. We know a priori which samples are blue and which are red. Now, however, a new sample has arrived &#8211; a green one. Our task is to determine whether this sample better fits with the reds or the blues. As you might guess, the simplest way to assign class A or B to a new sample is to calculate the distance between our sample and other points. Why does KNN have a &#8216;K&#8216; in its name? The &#8216;K&#8216; represents the number of nearest neighbors used to predict a classification. How do we calculate distance between samples? The easiest way to calculate the distance is to use a formula we all know from primary school, called the Euclidean distance. Of course, there are other algorithms that are better depending on the distribution of our data. ( x₂ &#8211; x₁ ) 2 + ( y₂ &#8211; y₁ ) 2 Just code this function def euclidean_distance(a, b): return np.sqrt(np.sum(a - b) ** 2) Now, we need to find the K nearest neighbors. First, we need to calculate the distance between each point and the test point. def get_neighbors(X, y, test_point, k): distances = [] for i in range(len(X)): distance = euclidean_distance(X[i], test_point) distances.append((X[i], y[i], distance)) distances.sort(key=lambda x: x[2]) neighbors = distances[:k] return neighbors In this step, we will calculate class for our test point. This is the result of get_neighbors function. As you can see, we have three instances of class 0 and two instances of class 1. Therefore, when the KNN algorithm is run on this data with K equal to 5, it will classify the test point as class 0, since it is nearest to this class. This is how it looks like Our test point has three connections with the blue ones and only two connections with the red ones. d(P, Q) = &#x2211; i 1 ^ n ( ( p _ i &#8211; q _ i ) ^ 2 ) Our function for calculating the Euclidean distance, called euclidean_distance, is designed to solve real-life problems that are not limited to two dimensions but can also handle n-dimensional scenarios.</p>
<p>The post <a href="https://pawelmajewski.com/understanding-k-nearest-neighbors-knn-essential-machine-learning-algorithm/">Understanding K-Nearest-Neighbors (KNN) – Essential Machine Learning Algorithm</a> first appeared on <a href="https://pawelmajewski.com">Software Developer's Tour</a>.</p>]]></description>
										<content:encoded><![CDATA[<div data-elementor-type="wp-post" data-elementor-id="8875" class="elementor elementor-8875">
				<div class="elementor-element elementor-element-f7b3b04 e-flex e-con-boxed wpr-particle-no wpr-jarallax-no wpr-parallax-no wpr-sticky-section-no wpr-column-slider-no wpr-equal-height-no e-con e-parent" data-id="f7b3b04" data-element_type="container" data-e-type="container">
					<div class="e-con-inner">
				<div class="elementor-element elementor-element-55e1baa elementor-widget elementor-widget-heading" data-id="55e1baa" data-element_type="widget" data-e-type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-default">A quick introduction to this algorithm</h2>				</div>
				</div>
					</div>
				</div>
		<div class="elementor-element elementor-element-c0b1357 e-flex e-con-boxed wpr-particle-no wpr-jarallax-no wpr-parallax-no wpr-sticky-section-no wpr-column-slider-no wpr-equal-height-no e-con e-parent" data-id="c0b1357" data-element_type="container" data-e-type="container">
					<div class="e-con-inner">
				<div class="elementor-element elementor-element-2c150bb elementor-widget elementor-widget-text-editor" data-id="2c150bb" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>KNN is used to determine the class of our sample data. To understand this more clearly, please take a look at the plot below. We have two groups of samples: <strong>blue</strong> ones and <strong>red</strong> ones. We know a priori which samples are blue and which are red. Now, however, a new sample has arrived &#8211; a green one. Our task is to determine whether this sample better fits with the reds or the blues.</p>								</div>
				</div>
					</div>
				</div>
		<div class="elementor-element elementor-element-42c4d11 e-flex e-con-boxed wpr-particle-no wpr-jarallax-no wpr-parallax-no wpr-sticky-section-no wpr-column-slider-no wpr-equal-height-no e-con e-parent" data-id="42c4d11" data-element_type="container" data-e-type="container">
					<div class="e-con-inner">
				<div class="elementor-element elementor-element-aab2dba elementor-widget elementor-widget-image" data-id="aab2dba" data-element_type="widget" data-e-type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img loading="lazy" decoding="async" loading="lazy" width="549" height="413" src="https://pawelmajewski.com/wp-content/uploads/2024/10/plot1.png" class="attachment-large size-large wp-image-8877" alt="plot1" srcset="https://pawelmajewski.com/wp-content/uploads/2024/10/plot1.png 549w, https://pawelmajewski.com/wp-content/uploads/2024/10/plot1-300x226.png 300w" sizes="auto, (max-width: 549px) 100vw, 549px" />															</div>
				</div>
				<div class="elementor-element elementor-element-92b4dba elementor-widget elementor-widget-text-editor" data-id="92b4dba" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>As you might guess, the simplest way to assign class A or B to a new sample is to calculate the distance between our sample and other points. Why does KNN have a &#8216;<strong>K</strong>&#8216; in its name? The &#8216;<strong>K</strong>&#8216; represents the number of nearest neighbors used to predict a classification.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-953199e elementor-widget elementor-widget-heading" data-id="953199e" data-element_type="widget" data-e-type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-default">How do we calculate distance between samples?</h2>				</div>
				</div>
				<div class="elementor-element elementor-element-cf04ff3 elementor-widget elementor-widget-text-editor" data-id="cf04ff3" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>The easiest way to calculate the distance is to use a formula we all know from primary school, called the <a title="Euclidean distance" href="https://en.wikipedia.org/wiki/Euclidean_distance" target="_blank" rel="noopener"><strong>Euclidean distance</strong></a>. Of course, there are other algorithms that are better depending on the distribution of our data.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-4608017 elementor-widget elementor-widget-html" data-id="4608017" data-element_type="widget" data-e-type="widget" data-widget_type="html.default">
				<div class="elementor-widget-container">
					    <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
        <msqrt>
            <mrow>
                <msup>
                    <mrow>
                        <mo>(</mo>
                        <mi>x</mi><mo>₂</mo> <mo>-</mo> <mi>x</mi><mo>₁</mo>
                        <mo>)</mo>
                    </mrow>
                    <mn>2</mn>
                </msup>
                <mo>+</mo>
                <msup>
                    <mrow>
                        <mo>(</mo>
                        <mi>y</mi><mo>₂</mo> <mo>-</mo> <mi>y</mi><mo>₁</mo>
                        <mo>)</mo>
                    </mrow>
                    <mn>2</mn>
                </msup>
            </mrow>
        </msqrt>
    </math>				</div>
				</div>
				<div class="elementor-element elementor-element-9af9130 elementor-widget elementor-widget-text-editor" data-id="9af9130" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>Just code this function</p>								</div>
				</div>
				<div class="elementor-element elementor-element-68b2c7f elementor-widget elementor-widget-code-block-for-elementor" data-id="68b2c7f" data-element_type="widget" data-e-type="widget" data-widget_type="code-block-for-elementor.default">
				<div class="elementor-widget-container">
					<pre class='line-numbers theme-okaidia' data-show-toolbar='yes'><code class='language-python'>def euclidean_distance(a, b):
  return np.sqrt(np.sum(a - b) ** 2)</code></pre>				</div>
				</div>
				<div class="elementor-element elementor-element-3a36398 elementor-widget elementor-widget-text-editor" data-id="3a36398" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>Now, we need to find the K nearest neighbors. First, we need to calculate the distance between each point and the test point.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-70385a8 elementor-widget elementor-widget-code-block-for-elementor" data-id="70385a8" data-element_type="widget" data-e-type="widget" data-widget_type="code-block-for-elementor.default">
				<div class="elementor-widget-container">
					<pre class='line-numbers theme-okaidia' data-show-toolbar='yes'><code class='language-javascript'>def get_neighbors(X, y, test_point, k):
    distances = []
    for i in range(len(X)):
        distance = euclidean_distance(X[i], test_point)
        distances.append((X[i], y[i], distance))
    distances.sort(key=lambda x: x[2])
    neighbors = distances[:k]
    return neighbors</code></pre>				</div>
				</div>
				<div class="elementor-element elementor-element-d553057 elementor-widget elementor-widget-text-editor" data-id="d553057" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>In this step, we will calculate class for our test point.</p><p>This is the result of <strong>get_neighbors</strong> function.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-91e193a elementor-widget elementor-widget-image" data-id="91e193a" data-element_type="widget" data-e-type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img loading="lazy" decoding="async" loading="lazy" width="671" height="259" src="https://pawelmajewski.com/wp-content/uploads/2024/10/neighbors.png" class="attachment-large size-large wp-image-8881" alt="neighbors" srcset="https://pawelmajewski.com/wp-content/uploads/2024/10/neighbors.png 671w, https://pawelmajewski.com/wp-content/uploads/2024/10/neighbors-300x116.png 300w" sizes="auto, (max-width: 671px) 100vw, 671px" />															</div>
				</div>
				<div class="elementor-element elementor-element-d66cf33 elementor-widget elementor-widget-text-editor" data-id="d66cf33" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>As you can see, we have three instances of class 0 and two instances of class 1. Therefore, when the KNN algorithm is run on this data with <strong>K</strong> equal to 5, it will classify the test point as class 0, since it is nearest to this class.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-b9d16a6 elementor-widget elementor-widget-text-editor" data-id="b9d16a6" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>This is how it looks like</p>								</div>
				</div>
				<div class="elementor-element elementor-element-49f0611 elementor-widget elementor-widget-image" data-id="49f0611" data-element_type="widget" data-e-type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img loading="lazy" decoding="async" loading="lazy" width="555" height="455" src="https://pawelmajewski.com/wp-content/uploads/2024/10/pobrane-1.png" class="attachment-large size-large wp-image-8882" alt="final plot" srcset="https://pawelmajewski.com/wp-content/uploads/2024/10/pobrane-1.png 555w, https://pawelmajewski.com/wp-content/uploads/2024/10/pobrane-1-300x246.png 300w" sizes="auto, (max-width: 555px) 100vw, 555px" />															</div>
				</div>
				<div class="elementor-element elementor-element-80d39b3 elementor-widget elementor-widget-text-editor" data-id="80d39b3" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>Our test point has three connections with the blue ones and only two connections with the red ones.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-59ae042 elementor-widget elementor-widget-html" data-id="59ae042" data-element_type="widget" data-e-type="widget" data-widget_type="html.default">
				<div class="elementor-widget-container">
					    <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
        <mrow>
            <mo>d(P, Q) =</mo>
            <msqrt>
                <mrow>
                    <mo>&#x2211;</mo>
                    <msub>
                        <mi>i</mi>
                        <mn>1</mn>
                    </msub>
                    <mo>^</mo>
                    <mi>n</mi>
                    <mo>(</mo>
                    <mo>(</mo>
                    <mi>p</mi>
                    <mo>_</mo>
                    <mi>i</mi>
                    <mo>-</mo>
                    <mi>q</mi>
                    <mo>_</mo>
                    <mi>i</mi>
                    <mo>)</mo>
                    <mo>^</mo>
                    <mn>2</mn>
                    <mo>)</mo>
                </mrow>
            </msqrt>
        </mrow>
    </math>				</div>
				</div>
				<div class="elementor-element elementor-element-dcd7e76 elementor-widget elementor-widget-text-editor" data-id="dcd7e76" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>Our function for calculating the <strong>Euclidean distance</strong>, called <strong><code>euclidean_distance</code></strong>, is designed to solve real-life problems that are not limited to two dimensions but can also handle n-dimensional scenarios.</p>								</div>
				</div>
					</div>
				</div>
				</div><p>The post <a href="https://pawelmajewski.com/understanding-k-nearest-neighbors-knn-essential-machine-learning-algorithm/">Understanding K-Nearest-Neighbors (KNN) – Essential Machine Learning Algorithm</a> first appeared on <a href="https://pawelmajewski.com">Software Developer's Tour</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://pawelmajewski.com/understanding-k-nearest-neighbors-knn-essential-machine-learning-algorithm/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>A Step-by-Step Guide to Web Scraping for Beginners</title>
		<link>https://pawelmajewski.com/a-step-by-step-guide-to-web-scraping-for-beginners/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-step-by-step-guide-to-web-scraping-for-beginners</link>
					<comments>https://pawelmajewski.com/a-step-by-step-guide-to-web-scraping-for-beginners/#respond</comments>
		
		<dc:creator><![CDATA[Paweł Majewski]]></dc:creator>
		<pubDate>Sat, 21 Jun 2025 08:38:00 +0000</pubDate>
				<category><![CDATA[Data Science]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Scraping]]></category>
		<guid isPermaLink="false">https://pawelmajewski.com/?p=8855</guid>

					<description><![CDATA[<p>In this article, I would like to raise the subject of web scraping. Before we start, we have to consider web scraping on several layers: legal and ethical.  Let&#8217;s tackle the topic of the legality of web scraping first. Fundamentally, the law depends on the country you live in. You should remember about: Authors&#8217; right Terms of Service General Data Protection Regulation (GDPR, European Union) Computer Fraud and Abuse Act (CFAA, USA) Outside the regulations you have to make sure that you are not affecting on target&#8217;s infrastructure by for example DDOSing target&#8217;s site. Let&#8217;s get to practice We want to get all titles from the blog section. When we analyze the blog section, we can see that the title is an a tag inside a div with the class blog-page-title. The steps we need to take to accomplish our task: 1. Go to the website. 2. Wait for the page to load until there is a div with the class &#8220;blog-page-title&#8221; and an a tag inside it. 3. Find the a tag inside the div with the class mentioned above. 4. Print the text of these a tags. from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC url = &#34;https://pawelmajewski.com/blog&#34; driver = webdriver.Chrome() driver.get(url) div_class = &#34;blog-page-title&#34; wait = WebDriverWait(driver, 3) wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, f&#34;div.{div_class} a&#34;))) a_tags = driver.find_elements(By.CSS_SELECTOR, f&#34;div.{div_class} a&#34;) for a_tag in a_tags: print(a_tag.text) driver.quit() I recommend using the Selenium library both for writing your own web scrapers as well as for writing, for example, integration tests.</p>
<p>The post <a href="https://pawelmajewski.com/a-step-by-step-guide-to-web-scraping-for-beginners/">A Step-by-Step Guide to Web Scraping for Beginners</a> first appeared on <a href="https://pawelmajewski.com">Software Developer's Tour</a>.</p>]]></description>
										<content:encoded><![CDATA[<div data-elementor-type="wp-post" data-elementor-id="8855" class="elementor elementor-8855">
				<div class="elementor-element elementor-element-4d1f27a e-flex e-con-boxed wpr-particle-no wpr-jarallax-no wpr-parallax-no wpr-sticky-section-no wpr-column-slider-no wpr-equal-height-no e-con e-parent" data-id="4d1f27a" data-element_type="container" data-e-type="container">
					<div class="e-con-inner">
				<div class="elementor-element elementor-element-5063eac elementor-widget elementor-widget-text-editor" data-id="5063eac" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>In this article, I would like to raise the subject of <strong>web scraping</strong>.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-163ebe3 elementor-widget elementor-widget-text-editor" data-id="163ebe3" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>Before we start, we have to consider web scraping on several layers: legal and ethical.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-7775128 elementor-widget elementor-widget-text-editor" data-id="7775128" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<div class="flex max-w-full flex-col flex-grow"><div class="min-h-[20px] text-message flex w-full flex-col items-end gap-2 whitespace-pre-wrap break-words [.text-message+&amp;]:mt-5 overflow-x-auto" dir="auto" data-message-author-role="assistant" data-message-id="59ca1973-cf4a-4b35-aa6b-9a89f1ea3639"><div class="flex w-full flex-col gap-1 empty:hidden first:pt-[3px]"><div class="markdown prose w-full break-words dark:prose-invert dark"><p><strong> Let&#8217;s tackle the topic of the legality of web scraping first.</strong></p></div></div></div></div>								</div>
				</div>
				<div class="elementor-element elementor-element-26264d9 elementor-widget elementor-widget-text-editor" data-id="26264d9" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>Fundamentally, the law depends on the country you live in. You should remember about:</p><p><strong>Authors&#8217; right</strong></p><p><strong>Terms of Service</strong></p><p><strong>General Data Protection Regulation (GDPR, European Union)</strong></p><p><strong>Computer Fraud and Abuse Act (CFAA, USA)</strong></p><p>Outside the regulations you have to make sure that you are not affecting on target&#8217;s infrastructure by for example <strong>DDOSing</strong> target&#8217;s site.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-b54eae8 elementor-widget elementor-widget-text-editor" data-id="b54eae8" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p><strong>Let&#8217;s get to practice</strong></p>								</div>
				</div>
				<div class="elementor-element elementor-element-2f03c68 elementor-widget elementor-widget-image" data-id="2f03c68" data-element_type="widget" data-e-type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img loading="lazy" decoding="async" loading="lazy" width="1024" height="682" src="https://pawelmajewski.com/wp-content/uploads/2024/09/website_pawel_majewski-1024x682.png" class="attachment-large size-large wp-image-8865" alt="website" srcset="https://pawelmajewski.com/wp-content/uploads/2024/09/website_pawel_majewski-1024x682.png 1024w, https://pawelmajewski.com/wp-content/uploads/2024/09/website_pawel_majewski-300x200.png 300w, https://pawelmajewski.com/wp-content/uploads/2024/09/website_pawel_majewski-768x511.png 768w, https://pawelmajewski.com/wp-content/uploads/2024/09/website_pawel_majewski-1536x1022.png 1536w, https://pawelmajewski.com/wp-content/uploads/2024/09/website_pawel_majewski.png 1974w" sizes="auto, (max-width: 1024px) 100vw, 1024px" />															</div>
				</div>
				<div class="elementor-element elementor-element-5573aa9 elementor-widget elementor-widget-text-editor" data-id="5573aa9" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>We want to get all titles from the blog section.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-223f0ab elementor-widget elementor-widget-text-editor" data-id="223f0ab" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>When we analyze the blog section, we can see that the title is an <code>a</code> tag inside a <code>div</code> with the class <code>blog-page-title</code>.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-e4be852 elementor-widget elementor-widget-image" data-id="e4be852" data-element_type="widget" data-e-type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img loading="lazy" decoding="async" loading="lazy" width="1024" height="552" src="https://pawelmajewski.com/wp-content/uploads/2024/09/Screenshot_19-1024x552.png" class="attachment-large size-large wp-image-8867" alt="web browser code inspector" srcset="https://pawelmajewski.com/wp-content/uploads/2024/09/Screenshot_19-1024x552.png 1024w, https://pawelmajewski.com/wp-content/uploads/2024/09/Screenshot_19-300x162.png 300w, https://pawelmajewski.com/wp-content/uploads/2024/09/Screenshot_19-768x414.png 768w, https://pawelmajewski.com/wp-content/uploads/2024/09/Screenshot_19-1536x828.png 1536w, https://pawelmajewski.com/wp-content/uploads/2024/09/Screenshot_19-2048x1104.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" />															</div>
				</div>
					</div>
				</div>
		<div class="elementor-element elementor-element-d3b9198 e-flex e-con-boxed wpr-particle-no wpr-jarallax-no wpr-parallax-no wpr-sticky-section-no wpr-column-slider-no wpr-equal-height-no e-con e-parent" data-id="d3b9198" data-element_type="container" data-e-type="container">
					<div class="e-con-inner">
				<div class="elementor-element elementor-element-b2235ac elementor-widget elementor-widget-text-editor" data-id="b2235ac" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>The steps we need to take to accomplish our task:</p><ul><li>1. Go to the website.</li><li>2. Wait for the page to load until there is a <code>div</code> with the class &#8220;blog-page-title&#8221; and an <code>a</code> tag inside it.</li><li>3. Find the <code>a</code> tag inside the <code>div</code> with the class mentioned above.</li><li>4. Print the text of these <code>a</code> tags.</li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-93a0690 elementor-widget elementor-widget-code-block-for-elementor" data-id="93a0690" data-element_type="widget" data-e-type="widget" data-widget_type="code-block-for-elementor.default">
				<div class="elementor-widget-container">
					<pre class='line-numbers theme-okaidia' data-show-toolbar='yes'><code class='language-javascript'>from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

url = &quot;https://pawelmajewski.com/blog&quot;
driver = webdriver.Chrome()
driver.get(url)
div_class = &quot;blog-page-title&quot;
wait = WebDriverWait(driver, 3)
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, f&quot;div.{div_class} a&quot;)))
a_tags = driver.find_elements(By.CSS_SELECTOR, f&quot;div.{div_class} a&quot;)

for a_tag in a_tags:
    print(a_tag.text)

driver.quit()</code></pre>				</div>
				</div>
				<div class="elementor-element elementor-element-6d48a4e elementor-widget elementor-widget-text-editor" data-id="6d48a4e" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>I recommend using the Selenium library both for writing your own web scrapers as well as for writing, for example, integration tests.</p>								</div>
				</div>
					</div>
				</div>
				</div><p>The post <a href="https://pawelmajewski.com/a-step-by-step-guide-to-web-scraping-for-beginners/">A Step-by-Step Guide to Web Scraping for Beginners</a> first appeared on <a href="https://pawelmajewski.com">Software Developer's Tour</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://pawelmajewski.com/a-step-by-step-guide-to-web-scraping-for-beginners/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
