Yogi Yogi - 1 month ago 7
HTML Question

Python webscraping using beautiful soup

Extract between span span

nameList = soup.find_all("span", {"class":"answer-number"})
for item in nameList:
print('item.content[0]')


I wrote the above code, but it is not working. Please help. I want the number 6a from it.

Answer
>>> soup.findAll('span',{'class':'badgecount'})
[<span class="badgecount">9</span>, <span class="badgecount">23</span>, <span class="badgecount">51</span>, <span class="badgecount">8</span>, <span class="badgecount">40</span>, <span class="badgecount">83</span>, <span class="badgecount">20</span>, <span class="badgecount">88</span>, <span class="badgecount">104</span>, <span class="badgecount">3</span>, <span class="badgecount">22</span>, <span class="badgecount">39</span>, <span class="badgecount">1</span>, <span class="badgecount">12</span>, <span class="badgecount">45</span>]
>>> spans=soup.findAll('span',{'class':'badgecount'})
>>> for span in spans:
    print span.text


9
23
51
8
40
83
20
88
104
3
22
39
1
12
45
Comments