<?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 Muhammad on Medium]]></title>
        <description><![CDATA[Stories by Muhammad on Medium]]></description>
        <link>https://medium.com/@muhammadraza0047?source=rss-865bf23acc10------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ANyovH8Tkz9d_pftmAcVBw.jpeg</url>
            <title>Stories by Muhammad on Medium</title>
            <link>https://medium.com/@muhammadraza0047?source=rss-865bf23acc10------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 09:55:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@muhammadraza0047/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[Web Scraping in Bash]]></title>
            <link>https://medium.com/@muhammadraza0047/web-scraping-in-bash-ce2ca47209ed?source=rss-865bf23acc10------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce2ca47209ed</guid>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[bash-script]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Muhammad]]></dc:creator>
            <pubDate>Wed, 20 Sep 2023 15:24:24 GMT</pubDate>
            <atom:updated>2023-09-20T15:24:24.239Z</atom:updated>
            <content:encoded><![CDATA[<p>In the realm of web scraping, Python often takes the spotlight with robust libraries such as BeautifulSoup and Scrapy. But did you know that web scraping can also be accomplished using Bash scripting? In this blog post, we’ll delve into a Bash script that extracts links and titles from a webpage and stores them in a CSV file.</p><p>Spending most of my workday in the terminal, I’ve become intimately familiar with writing Bash automation scripts. However, to add a creative twist, I ventured into the world of web scraping using Bash. While Bash excels at scripting, I discovered its hidden talents in web scraping, which I’m excited to share in this blog post.</p><h3>The Bash Script</h3><pre>#!/bin/bash<br><br># Define the URL to scrape<br>base_url=&quot;https://lite.cnn.com&quot;<br>url=&quot;https://lite.cnn.com/&quot;<br><br># Create a CSV file and add a header<br>echo &quot;Link,Title&quot; &gt; cnn_links.csv<br><br># Extract links and titles and save them to the CSV file<br>link_array=($(curl -s &quot;$url&quot; | awk -F &#39;href=&quot;&#39; &#39;/&lt;a/{gsub(/&quot;.*/, &quot;&quot;, $2); print $2}&#39;))<br><br>for link in &quot;${link_array[@]}&quot;; do<br>    full_link=&quot;${base_url}${link}&quot;<br>    title=$(curl -s &quot;$full_link&quot; | grep -o &#39;&lt;title[^&gt;]*&gt;[^&lt;]*&lt;/title&gt;&#39; | sed -e &#39;s/&lt;title&gt;//g&#39; -e &#39;s/&lt;\/title&gt;//g&#39;)<br>    echo &quot;\&quot;$full_link\&quot;,\&quot;$title\&quot;&quot; &gt;&gt; cnn_links.csv<br>done<br><br>echo &quot;Scraping and CSV creation complete. Links and titles saved to &#39;cnn_links.csv&#39;.&quot;</pre><h3>How it Works?</h3><p>This Bash script accomplishes the following:</p><ol><li>It defines the base URL and the URL of the webpage you want to scrape.</li><li>It creates a CSV file named cnn_links.csv with a header row containing “Link” and “Title” columns.</li><li>Using curl, it fetches the HTML content of the specified webpage and extracts all the links found within anchor tags (&lt;a&gt;) using awk.</li><li>It then iterates through the array of links and extracts the page titles by making additional curl requests to each link.</li><li>Finally, it appends the extracted links and titles to the CSV file in the desired format.</li></ol><h3>Breaking it down further</h3><ol><li>grep -o &#39;&lt;title[^&gt;]*&gt;[^&lt;]*&lt;/title&gt;&#39; extracts the page title from the HTML content using regular expressions.:</li><li>-o option tells grep to only output the matched part of the input text.</li><li>&lt;title[^&gt;]*&gt; matches the opening &lt;title&gt; tag and any attributes (e.g., &lt;title attribute=&quot;value&quot;&gt;), if present.</li><li>[^&lt;]* matches any characters that are not &lt; (i.e., the text within the &lt;title&gt; tag). &lt;/title&gt; matches the closing &lt;/title&gt; tag.</li><li>&lt;/title&gt; matches the closing &lt;/title&gt; tag.</li><li>sed -e &#39;s/&lt;title&gt;//g&#39; -e &#39;s/&lt;\/title&gt;//g&#39; removes the &lt;title&gt; and &lt;/title&gt; tags from the extracted title.`:</li><li>-e option allows specifying multiple commands to be executed by sed.</li><li>&#39;s/&lt;title&gt;//g&#39; is a sed command that replaces all occurrences of &lt;title&gt; with an empty string (i.e., removes the opening &lt;title&gt; tag).</li><li>&#39;s/&lt;\/title&gt;//g&#39; is another sed command that replaces all occurrences of &lt;/title&gt; with an empty string (i.e., removes the closing &lt;/title&gt; tag).</li></ol><p>Combining these commands:</p><ol><li>grep extracts the text within the &lt;title&gt; and &lt;/title&gt; tags.</li><li>sed then removes the tags themselves, leaving only the text content of the title.</li></ol><p>This command also uses awk to extract URLs from an HTML document. Let’s break it down step by step:</p><ol><li>awk -F &#39;href=&quot;&#39;:</li></ol><ul><li>awk is a text processing tool that operates on text files or input streams.</li><li>-F &#39;href=&quot;&#39; sets the field separator to &#39;href=&quot;&#39;. This means awk will treat &#39;href=&quot;&#39; as the delimiter for splitting input lines into fields.</li></ul><ol><li>&#39;/&lt;a/{gsub(/&quot;.*/, &quot;&quot;, $2); print $2}&#39;:</li></ol><ul><li>/&lt;a/ is a pattern that specifies a condition: lines containing &lt;a&gt;. This ensures that the following actions are only applied to lines containing anchor tags.</li><li>gsub(/&quot;.*/, &quot;&quot;, $2) is an awk function that globally substitutes (gsub) everything from the first double quote (&quot;) to the end of the field ($2) with an empty string. In this case, it effectively removes the opening &quot;, and the result is the URL.</li><li>print $2 prints the modified field (the extracted URL).</li></ul><p>So, this awk command looks for lines containing anchor tags (&lt;a&gt;) and extracts the URLs by removing everything before the first double quote (&quot;) in the href attribute. The extracted URLs are then printed as output.</p><h3>Conclusion</h3><p>So here’s a simple web scraper written in bash and uses cli tools such as awk, sed , grep and curl. As bash is available on most Linux system so it can be useful for scraping data from web pages without having to install any additional software. However, it is not as powerful as Python or other programming languages when it comes to web scraping. But it can be useful for simple tasks such as extracting links and titles from a webpage and I would not recommend using it for complex web scraping tasks.</p><p>Anyways this was a fun little script I created while learning about bash scripting and using cli tools such as awk , grep , sed and curl. I would still consider myself a beginner at this.</p><p>Lastly I hope you enjoyed reading this and got a chance to learn something new from this post and if you have any bash tips or used bash for similar task feel free to comment below as I would love to hear it.</p><p><em>If you loved this post, you can always support my work by </em><a href="https://www.buymeacoffee.com/mraza007"><em>buying me a coffee</em></a><em>. Also you can follow me on </em><a href="https://twitter.com/muhammad_o7"><em>Twitter</em></a><em>, and definitely tag me </em><a href="https://twitter.com/muhammad_o7"><em>@muhammad_o7</em></a><em>. when you share this post on twitter</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce2ca47209ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sending SMS using Python | Muhammad]]></title>
            <link>https://medium.com/@muhammadraza0047/sending-sms-using-python-muhammad-34c08ef506f5?source=rss-865bf23acc10------2</link>
            <guid isPermaLink="false">https://medium.com/p/34c08ef506f5</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[twilio]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[sms]]></category>
            <dc:creator><![CDATA[Muhammad]]></dc:creator>
            <pubDate>Fri, 07 Dec 2018 00:00:00 GMT</pubDate>
            <atom:updated>2019-12-05T04:05:36.424Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sending SMS using Python</h3><p>Whenever we talk about sending an SMS to our phone using any programming language the first thing that comes into our head is Twilio SMS library.But in this post we are going to avoid twilio and use python builtin module SMTPLIB I know it sounds crazy since SMTPLIB is used to send emails but we can also send text messages using that module. In order to send text message to your phone all you need to know is sms-gateway. So every carrier has their own sms-gateways and you can read more about it here <a href="https://en.wikipedia.org/wiki/SMS_gateway">SMS GATEWAYS</a>.</p><h3>SMS Gateways for each Carrier</h3><ul><li>AT&amp;T: [number]@txt.att.net</li><li>Sprint: [number]@messaging.sprintpcs.com or [number]@pm.sprint.com</li><li>T-Mobile: [number]@tmomail.net</li><li>Verizon: [number]@vtext.com</li><li>Boost Mobile: [number]@myboostmobile.com</li><li>Cricket: [number]@sms.mycricket.com</li><li>Metro PCS: [number]@mymetropcs.com</li><li>Tracfone: [number]@mmst5.tracfone.com</li><li>U.S. Cellular: [number]@email.uscc.net</li><li>Virgin Mobile: [number]@vmobl.com</li></ul><h3>So lets begin writing the script</h3><ul><li>First we need to import smtplib and MIME module that will help us structure our message by the way you can read more about MIME here <a href="https://en.wikipedia.org/wiki/MIME">Multipurpose Internet Mail Extensions (MIME)</a></li></ul><pre>import smtplib <br>from email.mime.text import MIMEText<br>from email.mime.multipart import MIMEMultipart<br><br>email = &quot;Your Email&quot;<br>pas = &quot;Your Pass&quot;<br><br>sms_gateway = &#39;number@tmomail.net&#39;<br># The server we use to send emails in our case it will be gmail but every email provider has a different smtp <br># and port is also provided by the email provider.<br>smtp = &quot;smtp.gmail.com&quot; <br>port = 587<br># This will start our email server<br>server = smtplib.SMTP(smtp,port)<br># Starting the server<br>server.starttls()<br># Now we need to login<br>server.login(email,pas)<br><br># Now we use the MIME module to structure our message.<br>msg = MIMEMultipart()<br>msg[&#39;From&#39;] = email<br>msg[&#39;To&#39;] = sms_gateway<br># Make sure you add a new line in the subject<br>msg[&#39;Subject&#39;] = &quot;You can insert anything\n&quot;<br># Make sure you also add new lines to your body<br>body = &quot;You can insert message here\n&quot;<br># and then attach that body furthermore you can also send html content.<br>msg.attach(MIMEText(body, &#39;plain&#39;))<br><br>sms = msg.as_string()<br><br>server.sendmail(email,sms_gateway,sms)</pre><p>So this was our simple python script that will allow you to send text messages to your phone. I hope you enjoyed this post if you think i missed any thing feel free to dm me on <a href="https://twitter.com/">twitter</a></p><p>Furthermore, here’s the python module that I wrote that allows you to send text messages without twilio. <a href="https://github.com/mraza007/terminal-text">termtext</a></p><p><em>Originally published at </em><a href="https://muhammadraza.me/2018/sending-sms-using-python/"><em>https://muhammadraza.me</em></a><em> on December 7, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34c08ef506f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>