In [2]:
from bs4 import BeautifulSoup
In [3]:
import requests
In [4]:
url = 'https://en.wikipedia.org/wiki/Transhumanism'
In [5]:
content = requests.get(url).content
In [6]:
soup = BeautifulSoup(content,'lxml')
In [7]:
tags = soup.findAll('div', {'class' : 'toc'})
In [8]:
len(tags)
Out[8]:
1
In [9]:
tag = soup.find('div', {'class' : 'toc'})
In [10]:
type(tag)
Out[10]:
bs4.element.Tag
In [11]:
links = tag.findAll('a')
In [12]:
links
Out[12]:
[<a href="#History"><span class="tocnumber">1</span> <span class="toctext">History</span></a>,
 <a href="#Early_transhumanist_thinking"><span class="tocnumber">1.1</span> <span class="toctext">Early transhumanist thinking</span></a>,
 <a href="#Artificial_intelligence_and_the_technological_singularity"><span class="tocnumber">1.2</span> <span class="toctext">Artificial intelligence and the technological singularity</span></a>,
 <a href="#Growth_of_transhumanism"><span class="tocnumber">1.3</span> <span class="toctext">Growth of transhumanism</span></a>,
 <a href="#Theory"><span class="tocnumber">2</span> <span class="toctext">Theory</span></a>,
 <a href="#Aims"><span class="tocnumber">2.1</span> <span class="toctext">Aims</span></a>,
 <a href="#Empathic_fallibility_and_conversational_consent"><span class="tocnumber">2.2</span> <span class="toctext">Empathic fallibility and conversational consent</span></a>,
 <a href="#Ethics"><span class="tocnumber">2.3</span> <span class="toctext">Ethics</span></a>,
 <a href="#Currents"><span class="tocnumber">2.4</span> <span class="toctext">Currents</span></a>,
 <a href="#Spirituality"><span class="tocnumber">2.5</span> <span class="toctext">Spirituality</span></a>,
 <a href="#Practice"><span class="tocnumber">3</span> <span class="toctext">Practice</span></a>,
 <a href="#Technologies_of_interest"><span class="tocnumber">3.1</span> <span class="toctext">Technologies of interest</span></a>,
 <a href="#Arts_and_culture"><span class="tocnumber">4</span> <span class="toctext">Arts and culture</span></a>,
 <a href="#Debate"><span class="tocnumber">5</span> <span class="toctext">Debate</span></a>,
 <a href="#Feasibility"><span class="tocnumber">5.1</span> <span class="toctext">Feasibility</span></a>,
 <a href="#Intrinsic_immorality"><span class="tocnumber">5.2</span> <span class="toctext">Intrinsic immorality</span></a>,
 <a href="#Loss_of_human_identity"><span class="tocnumber">5.3</span> <span class="toctext">Loss of human identity</span></a>,
 <a href="#Socioeconomic_effects"><span class="tocnumber">5.4</span> <span class="toctext">Socioeconomic effects</span></a>,
 <a href="#Specter_of_coercive_eugenicism"><span class="tocnumber">5.5</span> <span class="toctext">Specter of coercive eugenicism</span></a>,
 <a href="#Existential_risks"><span class="tocnumber">5.6</span> <span class="toctext">Existential risks</span></a>,
 <a href="#See_also"><span class="tocnumber">6</span> <span class="toctext">See also</span></a>,
 <a href="#References"><span class="tocnumber">7</span> <span class="toctext">References</span></a>,
 <a href="#Further_reading"><span class="tocnumber">8</span> <span class="toctext">Further reading</span></a>,
 <a href="#External_links"><span class="tocnumber">9</span> <span class="toctext">External links</span></a>]
In [15]:
for link in links:
  File "<ipython-input-15-2d6a5e14abd4>", line 1
    for link in links:
                      ^
SyntaxError: unexpected EOF while parsing
In [16]:
print (link.text)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-16-5c80d6661c4d> in <module>()
----> 1 print (link.text)

NameError: name 'link' is not defined
In [ ]: