1#start
2
3
4from bs4 import BeautifulSoup
5import requests
6
7req = requests.get('https://www.slickcharts.com/sp500')
8soup = BeautifulSoup(req.text, 'html.parser')
1>>> from bs4 import BeautifulSoup
2>>> soup = BeautifulSoup("<p>Some<b>bad<i>HTML")
3>>> print soup.prettify()
4<html>
5<body>
6<p>
7Some
8<b>
9bad
10<i>
11HTML
12</i>
13</b>
14</p>
15</body>
16</html>
17>>> soup.find(text="bad")
18u'bad'
19>>> soup.i
20<i>HTML</i>
21#
22>>> soup = BeautifulSoup("<tag1>Some<tag2/>bad<tag3>XML", "xml")
23#
24>>> print soup.prettify()
25<?xml version="1.0" encoding="utf-8">
26<tag1>
27Some
28<tag2 />
29bad
30<tag3>
31XML
32</tag3>
33</tag1>
34
1li = soup.find('li', {'class': 'text'})
2children = li.findChildren("a" , recursive=False)
3for child in children:
4 print child