python - Tag inside of beautifulsoup not working -


This code does not print the list of companies in the form of reqiured. It does not enter the first tag if I click on the "print" I write a text '' It does not print inside the first tag, the beautiful soup is working for a different code written for different sites. Any suggestions are not doing this work?

< Import from bs4 import beautiful soup urlib request = urllib.urlopen ('http://www.stockmarketsreview.com/companies_sp500/') html = request.read () Sou Request.close () soup = beautiful soup (html) for tags in p.find_all ('div', {'class': 'mainContent'}). For tags in tag. Find_all ('tr'): column For Row.find_all ('td'): print column.text

I have beautiful scenes 3 And it works correctly:

  Import Import Import urlib Beautiful soup as request = urllib.urlopen ('http://www.stockmarketsreview.com/companies_sp500 / ') Html = request.read () Request.close () Try soup = B. SundarSupa (HTML): Tags = soup.fandall (' div ', attrs = {' class': 'mainContent'}) For tags in tag: try: table = tag. Fund all ('table') print '# table =' + str (lane) bles : Rows for the row in lines = tag.findle ('tr'): try: column = row.finds for columns in your column ('td'): print column. Except the text: e = 1 # print 'Caught error' + Getting the TD tag under the str (stroke) # It is okay because in some rows & lt; Th & gt; not, & lt; Td> Except: Print 'Capture error' under '+ str (table)' prints except printing: 'Under' print tag 'Seed tag' 'stroke error' except 'str (tag): print' caught error disk Getting the tag ' 

I believe you'll need to replace' findAll 'with' find_all '.

The output looks like this: Enter image details here


Comments