How to get the title of links in the html page using BeautifulSoup python?
<p>Consider the html :</p>

<pre><code>&lt;li&gt;&lt;img alt="SangamUniversity-animated" class="newimg" src="images/new_animated.gif" /&gt;&lt;a href="pdffiles/Special Exam_Aug_2016.pdf" target="_blank"&gt; Student Notice &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;img alt="SangamUniversity-animated" class="newimg" src="images/new_animated.gif" /&gt;&lt;a href="pdffiles/Sangam_University_Bus_Route_Chart_Aug16.pdf" style="font-size:14px" target="_blank"&gt;UPDATED BUS ROUTE &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;img alt="SangamUniversity-animated" class="newimg" src="images/new_animated.gif" /&gt;&lt;a href="pdffiles/Sangam_University_Faculty_Requirement_Aug2016.jpg" target="_blank"&gt;Application are invited &lt;/a&gt;&lt;/li&gt;
</code></pre>

<p>I want to extract the following titles and save them in a <code>list</code>:</p>

<pre><code>Student Notice
UPDATED BUS ROUTE
Application are invited
</code></pre>

<p>How can I do it using <code>urllib2</code> and <code>BeautifulSoup</code>?</p>

<p>Which python and BeautifulSoup do you use?
In case of python2x and BS v. 3:</p>

<pre><code>from BeautifulSoup import BeautifulSoup

text = """&lt;li&gt;&lt;img alt="SangamUniversity-animated" class="newimg" src="images/new_animated.gif" /&gt;&lt;a href="pdffiles/Special Exam_Aug_2016.pdf" target="_blank"&gt; Student Notice &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;img alt="SangamUniversity-animated" class="newimg" src="images/new_animated.gif" /&gt;&lt;a href="pdffiles/Sangam_University_Bus_Route_Chart_Aug16.pdf" style="font-size:14px" target="_blank"&gt;UPDATED BUS ROUTE &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;img alt="SangamUniversity-animated" class="newimg" src="images/new_animated.gif" /&gt;&lt;a href="pdffiles/Sangam_University_Faculty_Requirement_Aug2016.jpg" target="_blank"&gt;Application are invited &lt;/a&gt;&lt;/li&gt;"""

soup = BeautifulSoup(text)

for link in soup.findAll('a'):
    print link.contents[0]
</code></pre>

<p>BS 4 a bit differs:</p>

<pre><code>soup = BeautifulSoup(text, 'html.parser')

for link in soup.find_all('a'):
    print link.contents[0]
</code></pre>

python web-scraping beautifulsoup urllib2