[quote='snippsat' pid='55382' dateline='1534295409']
Sure can wonder if run again
[/quote]
Just to mention that I still haven't finished the whole program. The main work is still to be done!
Will use your suggestions. Thank you!
[quote='snippsat' pid='55382' dateline='1534295409']
The parsing is already done so
[/output]
I don't understand this. I thought that parsing should make selectors available.
Also, I'm not quite satisfied with your solution ( sorry for that, not trying to be inpolite! ). The goal of this exercise is to enlist all mathematicians, one in each row. Adding limitation to 5 is not what should be done here.
I made some modifications...
Sure can wonder if run again
[/quote]
Just to mention that I still haven't finished the whole program. The main work is still to be done!
Will use your suggestions. Thank you!
[quote='snippsat' pid='55382' dateline='1534295409']
The parsing is already done so
(html.select('li')):
will not work.[/output]
I don't understand this. I thought that parsing should make selectors available.
Also, I'm not quite satisfied with your solution ( sorry for that, not trying to be inpolite! ). The goal of this exercise is to enlist all mathematicians, one in each row. Adding limitation to 5 is not what should be done here.
I made some modifications...
def get_names(url): """ Downloads the page where the list of mathematicians is found and returns a list of strings, one per mathematician """ response = simple_get(url) if response is not None: html = BeautifulSoup(response, 'html.parser') names = set() # set ensures that you don’t end up with duplicate names. for li in html.select('li'): for name in li.text.split('\n'): if len(name) > 0: names.add(name.strip()) return str(names) # Raise an exception if we failed to get any data from the url raise Exception(f'Error retrieving contents at {format(url)}')
from bs4 import BeautifulSoup from mathematicians import get_names math_list = get_names('http://www.fabpedigree.com/james/mathmen.htm') print((math_list.split('\n')))
Output:['{\'Felix Christian Klein\', \'Felix Hausdorff\', \'Johannes Kepler\', \'Eudoxus of Cnidus\', \'Leonhard Euler\', \'James J. Sylvester\', \'Gaspard Monge\', \'Blaise Pascal\', \'Joseph Liouville\', \'Pythagoras of Samos\', "Jean le Rond d\'Alembert", \'Hipparchus of Nicaea\', \'Christiaan Huygens\', \'Omar al-Khayyám\', \'Georg Cantor\', \'Joseph-Louis Lagrange\', \'Pierre-Simon Laplace\', \'Isaac Newton\', \'William R. Hamilton\', \'Bernhard Riemann\', \'Élie Cartan\', \'Girolamo Cardano\', \'Stefan Banach\', \'M. E. Camille Jordan\', "Leonardo `Fibonacci\'", \'Siméon-Denis Poisson\', \'Bonaventura Cavalieri\', \'Archytas of Tarentum\', \'Gottfried W. Leibniz\', \'Johann Bernoulli\', \'Archimedes\', \'F. L. Gottlob Frege\', \'Giuseppe Peano\', \'Adrien M. Legendre\', \'Alfred Tarski\', \'Pappus of Alexandria\', \'George Pólya\', \'Pafnuti Chebyshev\', \'Karl W. T. Weierstrass\', \'Pierre de Fermat\', \'Emmy Noether\', \'Albert Einstein\', \'Michael F. Atiyah\', \'Srinivasa Ramanujan\', \'Charles Hermite\', \'Ernst E. Kummer\', \'Galileo Galilei\', \'Diophantus of Alexandria\', \'Arthur Cayley\', \'L.E.J. Brouwer\', \'Johann H. Lambert\', \'Richard Dedekind\', \'Carl F. Gauss\', \'Peter G. L. Dirichlet\', \'Alan M. Turing\', \'David Hilbert\', \'Aryabhata\', \'Carl G. J. Jacobi\', \'Panini of Shalatula\', \'Brahmagupta\', \'Atle Selberg\', \'Hermann K. H. Weyl\', \'Jean-Pierre Serre\', \'François Viète\', \'Godfrey H. Hardy\', \'Henri Poincaré\', \'Apollonius of Perga\', \'Hermann Minkowski\', \'Aristotle\', \'Carl Ludwig Siegel\', \'Évariste Galois\', \'George D. Birkhoff\', \'Jakob Steiner\', \'Marius Sophus Lie\', \'Bháscara (II) Áchárya\', \'Hermann G. Grassmann\', \'F. Gotthold Eisenstein\', \'Jacques Hadamard\', \'Euclid of Alexandria\', \'Joseph Fourier\', \'John E. Littlewood\', \'Shiing-Shen Chern\', \'Muhammed al-Khowârizmi\', \'Jean-Victor Poncelet\', \'Jacob Bernoulli\', \'Alhazen ibn al-Haytham\', \'Henri Léon Lebesgue\', \'F.E.J. Émile Borel\', \'Alexandre Grothendieck\', \'Julius Plücker\', \'André Weil\', \'John von Neumann\', \'Liu Hui\', \'Thales of Miletus\', \'Andrey N. Kolmogorov\', \'René Descartes\', \'Kurt Gödel\', \'Niels Abel\', \'Augustin Cauchy\', \'James C. Maxwell\'}']
why math_list.split('\n'))
doesn't bring desired outcome ( one line for one name )?