Free AI web copilot to create summaries, insights and extended knowledge, download it at here
1331
Abstract
screen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><h2 id="6261">2-Loading Webpages with request</h2><p id="1f31">The requests module helps to send HTTP requests in Python. So the next step is to inspect the required data classes from the complete source code. We select the card and click on the ‘Inspect Element’ option to get the source code of that particular section. You will get something similar to this:</p><figure id="18c7"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*wRNX7SsQePw7lk7uzT7cRw.png"><figcaption>Inspecting title</figcaption></figure><figure id="ddfd"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*tDkqbU4V2fVolKOPl5aoZg.png"><figcaption>Inspecting Price</figcaption></figure><p id="04fd">Now we need to write a function that could scrap the title and price from the webpage.</p><ul><li>Get the contents of the following URL using the <code>requests</code> module: <a href="https://finance.yahoo.com/quote/TSLA/"><b>https://finance.yahoo.com/quote/TSLA/</b></a></li><li>Find the title and price using class the name inspected from the webpage</li><li>Convert the string price to float</li><li>Call the function to send an email</li></ul>
<figure id="f051">
Options
<div>
<div>
<iframe class="gist-iframe" src="/gist/bilalkhann16/e543999cff6003e8f6381175432bd3cc.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><h2 id="a50a">3- Sending Emails in a standard format</h2><ul><li>Establish the SMTP connection at port 587</li><li>Start TLS based SMTP Session</li><li>Give the secret credentials along with the to and from email address.</li><li>Set Email Parameters</li><li>Terminate the SMTP Session</li></ul>
<figure id="6300">
<div>
<div>
<iframe class="gist-iframe" src="/gist/bilalkhann16/2e7b794b514e762c6c26a9ca114b17f8.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="7611">The complete code is available <a href="https://github.com/bilalkhann16/beautifulsoup-python/blob/master/tesla.py"><b>here</b></a>. Feel free to check it out.</p><p id="4c93">So that’s it! I hope you found it helpful, and also I hope that you have a nice day.</p><p id="e1b7">Till next time :) Happy Learning.</p><p id="7f2f">Bilal Khan.</p></article></body>