Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] Searching The Parse Tree Using BeautifulSoup

#1
Searching The Parse Tree Using BeautifulSoup

<div><h2>Introduction</h2>
<p>HTML (Hypertext Markup Language) consists of numerous tags and the data we need to extract lies inside those tags. Thus we need to find the right tags to extract what we need. Now, how do we find the right tags? We can do so with the help of <code data-enlighter-language="generic" class="EnlighterJSRAW">BeautifulSoup's </code>search methods.</p>
<p>Beautiful Soup has numerous methods for searching a parse tree. The two most popular and commonly methods are:</p>
<ol>
<li>&nbsp;<code>find()</code></li>
<li>&nbsp;<code>find_all()</code></li>
</ol>
<p>The other methods are quite similar in terms of their usage. Therefore, we will be focusing on the <code data-enlighter-language="generic" class="EnlighterJSRAW">find()</code> and<code data-enlighter-language="generic" class="EnlighterJSRAW"> find_all() </code>methods in this article. </p>
<p><img src="https://s.w.org/images/core/emoji/13.0.0/72x72/1f6a9.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> The following <em><strong>Example</strong></em><strong> </strong>will be used throughout this document while demonstrating the concepts:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">html_doc = """ &lt;html&gt;&lt;head&gt;&lt;title&gt;Searching Tree&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Searching Parse Tree In BeautifulSoup&lt;/h1&gt;&lt;/p&gt; &lt;p class="Main"&gt;Learning &lt;a href="https://docs.python.org/3/" class="language" id="python"&gt;Python&lt;/a&gt;,
&lt;a href="https://docs.oracle.com/en/java/" class="language" id="java"&gt;Java&lt;/a&gt; and
&lt;a href="https://golang.org/doc/" class="language" id="golang"&gt;Golang&lt;/a&gt;;
is fun!&lt;/p&gt; &lt;p class="Secondary"&gt;&lt;b&gt;Please subscribe!&lt;/b&gt;&lt;/p&gt;
&lt;p class="Secondary" id= "finxter"&gt;&lt;b&gt;copyright - FINXTER&lt;/b&gt;&lt;/p&gt; """
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc, "html.parser")</pre>
<h2>Types Of Filters </h2>
<p>There are different filters that can be passed into the <code data-enlighter-language="generic" class="EnlighterJSRAW">find()</code> and <code data-enlighter-language="generic" class="EnlighterJSRAW">find_all()</code> methods and it is crucial to have a clear understanding of these filters as they are used again and again, throughout the search mechanism. These filters can be used based on the tags:</p>
<ul>
<li>name, </li>
<li>attributes, </li>
<li>on the text of a string,</li>
<li>or a mix of these.</li>
</ul>
<h3>❖ <span class="has-inline-color has-black-color">A String</span></h3>
<p>When we pass a <strong>string </strong>to a search method then <strong>Beautiful Soup</strong> performs a match against that passed string. Let us have a look at an example and find the &lt;h1&gt; tags in the HTML document:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">print(soup.find_all('h1'))</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">[&lt;h1&gt;Searching Parse Tree In BeautifulSoup&lt;/h1&gt;]</pre>
<h3>❖ A <a href="https://blog.finxter.com/python-regex/" target="_blank" rel="noreferrer noopener">Regular Expression</a></h3>
<p>Passing a regular expression object allows Beautiful Soup to filter results according to that regular expression. In case you want to master the concepts of the regex module in Python, please refer to our <a href="https://blog.finxter.com/python-regex/" target="_blank" rel="noreferrer noopener"><strong>tutorial here</strong></a>. </p>
<p><strong>Note: </strong></p>
<ul>
<li>We need to import the <code>re</code> module to use a regular expression.</li>
<li>To get just the name of the tag instead of the entire content (tag+ content within the tag), use the <code data-enlighter-language="generic" class="EnlighterJSRAW">.name</code> attribute.</li>
</ul>
<p><strong>Example: </strong>The following code finds all instances of the tags starting with the letter “b”. </p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># finding regular expressions
for regular in soup.find_all(re.compile("^b")): print(regular.name)</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">body
b</pre>
<h3>❖ A <a href="https://blog.finxter.com/python-lists/" target="_blank" rel="noreferrer noopener">List</a></h3>
<p>Multiple tags can be passed into the search functions using a list a shown in the example below:</p>
<p><strong>Example:</strong> The following code finds all the &lt;a&gt; and &lt;b&gt; tags in the HTML document.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">for tag in soup.find_all(['a','b']): print(tag)</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;a class="language" href="https://docs.python.org/3/" id="python"&gt;Python&lt;/a&gt;
&lt;a class="language" href="https://docs.oracle.com/en/java/" id="java"&gt;Java&lt;/a&gt;
&lt;a class="language" href="https://golang.org/doc/" id="golang"&gt;Golang&lt;/a&gt;
&lt;b&gt;Please subscribe!&lt;/b&gt;</pre>
<h3>❖ A <a href="https://blog.finxter.com/python-cheat-sheet-functions-and-tricks/" target="_blank" rel="noreferrer noopener">function</a></h3>
<p>We can define a function and pass an element as its argument. The function returns&nbsp;<code>True</code>&nbsp;in case of a match, otherwise it returns&nbsp;<code>False</code>. </p>
<p><strong>Example: </strong>The following code defines a function which returns <code>True</code> for all <code data-enlighter-language="generic" class="EnlighterJSRAW">classes</code> that also have an <code data-enlighter-language="generic" class="EnlighterJSRAW">id </code>in the HTML document. We then pass this function to the <code data-enlighter-language="generic" class="EnlighterJSRAW">find_all()</code> method to get the desired output.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">def func(tag): return tag.has_attr('class') and tag.has_attr('id') for tag in soup.find_all(func): print(tag)</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;a class="language" href="https://docs.python.org/3/" id="python"&gt;Python&lt;/a&gt;
&lt;a class="language" href="https://docs.oracle.com/en/java/" id="java"&gt;Java&lt;/a&gt;
&lt;a class="language" href="https://golang.org/doc/" id="golang"&gt;Golang&lt;/a&gt;</pre>
<p>➠ Now that we have gone through the different kind of filters that we use with the search methods, we are well equipped to dive deep into the <code data-enlighter-language="generic" class="EnlighterJSRAW">find()</code> and <code data-enlighter-language="generic" class="EnlighterJSRAW">find_all()</code> methods. </p>
<h2><img src="https://s.w.org/images/core/emoji/13.0.0/72x72/2728.png" alt="✨" class="wp-smiley" style="height: 1em; max-height: 1em;" /> The <span class="has-inline-color has-luminous-vivid-orange-color">find()</span> Method</h2>
<p>The&nbsp;<code data-enlighter-language="generic" class="EnlighterJSRAW">find()</code>&nbsp;method is used to search for the occurrence of the first instance of a tag with the needed name.</p>
<p><strong>Syntax:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">find(name, attrs, recursive, string, **kwargs)</pre>
<p>➠ <code data-enlighter-language="generic" class="EnlighterJSRAW">find()</code> returns an object of type <strong>bs4.element.Tag</strong>.</p>
<p><strong>Example:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">print(soup.find('h1'), "\n")
print("RETURN TYPE OF find(): ",type(soup.find('h1')), "\n")
# note that only the first instance of the tag is returned
print(soup.find('a'))</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;h1&gt;Searching Parse Tree In BeautifulSoup&lt;/h1&gt; RETURN TYPE OF find(): &lt;class 'bs4.element.Tag'&gt; &lt;a class="language" href="https://docs.python.org/3/" id="python"&gt;Python&lt;/a&gt;</pre>
<p>➠ The above operation is the same as done by the <code data-enlighter-language="generic" class="EnlighterJSRAW">soup.h1</code> or soup <code data-enlighter-language="generic" class="EnlighterJSRAW">soup.a</code> which also returns the first instance of the given tag. So what’s, the difference? The <code data-enlighter-language="generic" class="EnlighterJSRAW">find()</code> method helps us to find a particular instance of a given tag using key-value pairs as shown in the example below:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">print(soup.find('a',id='golang'))</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;a class="language" href="https://golang.org/doc/" id="golang"&gt;Golang&lt;/a&gt;</pre>
<h2><img src="https://s.w.org/images/core/emoji/13.0.0/72x72/2728.png" alt="✨" class="wp-smiley" style="height: 1em; max-height: 1em;" /> The <span class="has-inline-color has-luminous-vivid-orange-color">find_all() </span>Method</h2>
<p>We saw that the <code data-enlighter-language="generic" class="EnlighterJSRAW">find()</code> method is used to search for the first tag. What if we want to find all instances of a tag or numerous instances of a given tag within the HTML document? The <code data-enlighter-language="generic" class="EnlighterJSRAW">find_all()</code> method, helps us to search for all tags with the given tag name and returns a <strong>list </strong>of type <strong>bs4.element.ResultSet</strong>. Since the items are returned in a list, they can be accessed with help of their index.</p>
<p><strong>Syntax:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">find_all(name, attrs, recursive, string, limit, **kwargs)</pre>
<p><strong>Example:</strong> Searching all instances of the ‘a’ tag in the HTML document.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">for tag in soup.find_all('a'): print(tag)</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;a class="language" href="https://docs.python.org/3/" id="python"&gt;Python&lt;/a&gt;
&lt;a class="language" href="https://docs.oracle.com/en/java/" id="java"&gt;Java&lt;/a&gt;
&lt;a class="language" href="https://golang.org/doc/" id="golang"&gt;Golang&lt;/a&gt;</pre>
<p>Now there are numerous other <strong>argument </strong>apart from the filters that we already discussed earlier. Let us have a look at them one by one.</p>
<h3>❖ The <span class="has-inline-color has-luminous-vivid-orange-color">name </span>Argument</h3>
<p>As stated earlier the name argument can be a string, a regular expression, a list, a function, or the value True.</p>
<p><strong>Example:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">for tag in soup.find_all('p'): print(tag)</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;p class="Main"&gt;Learning &lt;a class="language" href="https://docs.python.org/3/" id="python"&gt;Python&lt;/a&gt;,
&lt;a class="language" href="https://docs.oracle.com/en/java/" id="java"&gt;Java&lt;/a&gt; and
&lt;a class="language" href="https://golang.org/doc/" id="golang"&gt;Golang&lt;/a&gt;;
is fun!&lt;/p&gt;
&lt;p class="Secondary"&gt;&lt;b&gt;Please subscribe!&lt;/b&gt;&lt;/p&gt;</pre>
<h3>❖ The <span class="has-inline-color has-luminous-vivid-orange-color">keyword </span>Arguments</h3>
<p>Just like the <code data-enlighter-language="generic" class="EnlighterJSRAW">find()</code> method, <code data-enlighter-language="generic" class="EnlighterJSRAW">find_all()</code> also allows us to find particular instances of a tag. For example, if the <code>id</code> argument is passed, Beautiful Soup filters against each tag’s ‘id’ attribute and returns the result accordingly.</p>
<p><strong>Example:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">print(soup.find_all('a',id='java'))</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">[&lt;a class="language" href="https://docs.oracle.com/en/java/" id="java"&gt;Java&lt;/a&gt;]</pre>
<p>You can also pass the attributes as dictionary key-value pairs using the <code data-enlighter-language="generic" class="EnlighterJSRAW">attrs </code>argument.</p>
<p><strong>Example:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">print(soup.find_all('a', attrs={'id': 'java'}))</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">[&lt;a class="language" href="https://docs.oracle.com/en/java/" id="java"&gt;Java&lt;/a&gt;]</pre>
<h3>❖ Search Using <span class="has-inline-color has-luminous-vivid-orange-color">CSS Class</span></h3>
<p>Often we need to find a tag that has a certain CSS class, but the attribute, <code data-enlighter-language="generic" class="EnlighterJSRAW">class</code>, is a reserved keyword in Python. Thus, using <code>class</code> as a keyword argument will give a <strong>syntax error</strong>. Beautiful Soup 4.1.2 allows us to search a CSS class using the keyword <code>class_</code></p>
<p><strong>Example:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">print(soup.find_all('p', class_='Secondary'))</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">[&lt;p class="Secondary"&gt;&lt;b&gt;Please subscribe!&lt;/b&gt;&lt;/p&gt;]</pre>
<p>❖ Note: The above search will allow you to search all instances of the p tag with the class “Secondary” . But you can also filter searches based on multiple attributes, using a dictionary. </p>
<p><strong>Example: </strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">print(soup.find_all('p', attrs={'class': 'Secondary', 'id': 'finxter'}))</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">[&lt;p class="Secondary" id="finxter"&gt;&lt;b&gt;copyright - FINXTER&lt;/b&gt;&lt;/p&gt;]</pre>
<h3>❖ The <span class="has-inline-color has-luminous-vivid-orange-color">string </span>Argument</h3>
<p>The <strong>string </strong>argument allows us to search for strings instead of tags.</p>
<p><strong>Example:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">print(soup.find_all(string=["Python", "Java", "Golang"]))</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">['Python', 'Java', 'Golang']</pre>
<h3>❖ The <span class="has-inline-color has-luminous-vivid-orange-color">limit </span>Argument</h3>
<p>The <code>find_all()</code> method scans through the entire HTML document and returns all the matching tags and strings. This can be extremely tedious and take a lot of time if the document is large. So, you can limit the number of results by passing in the <code>limit</code> argument. </p>
<p><strong>Example: </strong>There are three links in the example HTML document, but this code only finds the first two:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">print(soup.find_all("a", limit=2))</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">[&lt;a class="language" href="https://docs.python.org/3/" id="python"&gt;Python&lt;/a&gt;, &lt;a class="language" href="https://docs.oracle.com/en/java/" id="java"&gt;Java&lt;/a&gt;]</pre>
<h2><img src="https://s.w.org/images/core/emoji/13.0.0/72x72/2728.png" alt="✨" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Other Search Methods</h2>
<p>We have successfully explored the most commonly used search methods, i.e., <code data-enlighter-language="generic" class="EnlighterJSRAW">find </code>and <code data-enlighter-language="generic" class="EnlighterJSRAW">find_all()</code>. Beautiful Soup also has other methods for searching the parse tree, but they are quite similar to what we already discussed above. The only differences are where they are used. Let us have a quick look at these methods.</p>
<ul>
<li><strong>find_parents()</strong> and <strong>find_parent()</strong>: these methods are used to traverse the parse tree upwards and look for a tag’s/string’s parent(s).</li>
<li><strong>find_next_siblings()</strong> and <strong>find_next_sibling()</strong>: these methods are used to find the next sibling(s) of an element in the HTML document.</li>
<li><strong>find_previous_siblings()</strong> and <strong>find_previous_sibling()</strong>: these methods are used to find and iterate over the sibling(s) that appear before the current element.</li>
<li><strong>find_all_next()</strong> and <strong>find_next()</strong>: these methods are used to find and iterate over the sibling(s) that appear after the current element.</li>
<li><strong>find_all_previous</strong> and <strong>find_previous()</strong>: these methods are used to find and iterate over the tags and strings that appear before the current element in the HTML document.</li>
</ul>
<p><strong>Example:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">current = soup.find('a', id='java')
print(current.find_parent())
print()
print(current.find_parents())
print()
print(current.find_previous_sibling())
print()
print(current.find_previous_siblings())
print()
print(current.find_next())
print()
print(current.find_all_next())
print()</pre>
<p><strong>Output:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;p class="Main"&gt;Learning &lt;a class="language" href="https://docs.python.org/3/" id="python"&gt;Python&lt;/a&gt;,
&lt;a class="language" href="https://docs.oracle.com/en/java/" id="java"&gt;Java&lt;/a&gt; and
&lt;a class="language" href="https://golang.org/doc/" id="golang"&gt;Golang&lt;/a&gt;;
is fun!&lt;/p&gt; [&lt;p class="Main"&gt;Learning &lt;a class="language" href="https://docs.python.org/3/" id="python"&gt;Python&lt;/a&gt;,
&lt;a class="language" href="https://docs.oracle.com/en/java/" id="java"&gt;Java&lt;/a&gt; and
&lt;a class="language" href="https://golang.org/doc/" id="golang"&gt;Golang&lt;/a&gt;;
is fun!&lt;/p&gt;, &lt;body&gt;
&lt;h1&gt;Searching Parse Tree In BeautifulSoup&lt;/h1&gt;
&lt;p class="Main"&gt;Learning &lt;a class="language" href="https://docs.python.org/3/" id="python"&gt;Python&lt;/a&gt;,
&lt;a class="language" href="https://docs.oracle.com/en/java/" id="java"&gt;Java&lt;/a&gt; and
&lt;a class="language" href="https://golang.org/doc/" id="golang"&gt;Golang&lt;/a&gt;;
is fun!&lt;/p&gt;
&lt;p class="Secondary"&gt;&lt;b&gt;Please subscribe!&lt;/b&gt;&lt;/p&gt;
&lt;p class="Secondary" id="finxter"&gt;&lt;b&gt;copyright - FINXTER&lt;/b&gt;&lt;/p&gt;
&lt;p class="Secondary"&gt;&lt;b&gt;Please subscribe!&lt;/b&gt;&lt;/p&gt;
&lt;/body&gt;, &lt;html&gt;&lt;head&gt;&lt;title&gt;Searching Tree&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Searching Parse Tree In BeautifulSoup&lt;/h1&gt;
&lt;p class="Main"&gt;Learning &lt;a class="language" href="https://docs.python.org/3/" id="python"&gt;Python&lt;/a&gt;,
&lt;a class="language" href="https://docs.oracle.com/en/java/" id="java"&gt;Java&lt;/a&gt; and
&lt;a class="language" href="https://golang.org/doc/" id="golang"&gt;Golang&lt;/a&gt;;
is fun!&lt;/p&gt;
&lt;p class="Secondary"&gt;&lt;b&gt;Please subscribe!&lt;/b&gt;&lt;/p&gt;
&lt;p class="Secondary" id="finxter"&gt;&lt;b&gt;copyright - FINXTER&lt;/b&gt;&lt;/p&gt;
&lt;p class="Secondary"&gt;&lt;b&gt;Please subscribe!&lt;/b&gt;&lt;/p&gt;
&lt;/body&gt;&lt;/html&gt;, &lt;html&gt;&lt;head&gt;&lt;title&gt;Searching Tree&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Searching Parse Tree In BeautifulSoup&lt;/h1&gt;
&lt;p class="Main"&gt;Learning &lt;a class="language" href="https://docs.python.org/3/" id="python"&gt;Python&lt;/a&gt;,
&lt;a class="language" href="https://docs.oracle.com/en/java/" id="java"&gt;Java&lt;/a&gt; and
&lt;a class="language" href="https://golang.org/doc/" id="golang"&gt;Golang&lt;/a&gt;;
is fun!&lt;/p&gt;
&lt;p class="Secondary"&gt;&lt;b&gt;Please subscribe!&lt;/b&gt;&lt;/p&gt;
&lt;p class="Secondary" id="finxter"&gt;&lt;b&gt;copyright - FINXTER&lt;/b&gt;&lt;/p&gt;
&lt;p class="Secondary"&gt;&lt;b&gt;Please subscribe!&lt;/b&gt;&lt;/p&gt;
&lt;/body&gt;&lt;/html&gt;] &lt;a class="language" href="https://docs.python.org/3/" id="python"&gt;Python&lt;/a&gt; [&lt;a class="language" href="https://docs.python.org/3/" id="python"&gt;Python&lt;/a&gt;] &lt;a class="language" href="https://golang.org/doc/" id="golang"&gt;Golang&lt;/a&gt; [&lt;a class="language" href="https://golang.org/doc/" id="golang"&gt;Golang&lt;/a&gt;, &lt;p class="Secondary"&gt;&lt;b&gt;Please subscribe!&lt;/b&gt;&lt;/p&gt;, &lt;b&gt;Please subscribe!&lt;/b&gt;, &lt;p class="Secondary" id="finxter"&gt;&lt;b&gt;copyright - FINXTER&lt;/b&gt;&lt;/p&gt;, &lt;b&gt;copyright - FINXTER&lt;/b&gt;, &lt;p class="Secondary"&gt;&lt;b&gt;Please subscribe!&lt;/b&gt;&lt;/p&gt;, &lt;b&gt;Please subscribe!&lt;/b&gt;]</pre>
<h2>Conclusion</h2>
<p>With that we come to the end of this article; I hope that after reading this article you can search elements within a parse tree with ease! Please <strong><a href="https://blog.finxter.com/subscribe" target="_blank" rel="noreferrer noopener">subscribe</a></strong> and <strong><a href="https://blog.finxter.com/" target="_blank" rel="noreferrer noopener">stay tuned</a></strong> for more interesting articles.</p>
<h2>Where to Go From Here?</h2>
<p>Enough theory, let’s get some practice!</p>
<p>To become successful in coding, you need to get out there and solve real problems for real people. That’s how you can become a six-figure earner easily. And that’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?</p>
<p><strong>Practice projects is how you sharpen your saw in coding!</strong></p>
<p>Do you want to become a code master by focusing on practical code projects that actually earn you money and solve problems for people?</p>
<p>Then become a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.</p>
<p>Join my free webinar <a rel="noreferrer noopener" href="https://blog.finxter.com/webinar-freelancer/" target="_blank">“How to Build Your High-Income Skill Python”</a> and watch how I grew my coding business online and how you can, too—from the comfort of your own home.</p>
<p><a href="https://blog.finxter.com/webinar-freelancer/" target="_blank" rel="noreferrer noopener">Join the free webinar now!</a></p>
<p>The post <a href="https://blog.finxter.com/searching-the-parse-tree-using-beautifulsoup/" target="_blank" rel="noopener noreferrer">Searching The Parse Tree Using BeautifulSoup</a> first appeared on <a href="https://blog.finxter.com/" target="_blank" rel="noopener noreferrer">Finxter</a>.</p>
</div>


https://www.sickgaming.net/blog/2020/12/...tifulsoup/
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016