Wednesday, January 11, 2017

Python BeautifulSoup Example


from urllib import urlopen
from bs4 import BeautifulSoup

url = ''

html = urlopen(url)

bsObj = BeautifulSoup(

# The markers are in a table, there are several tables on the page
# The Afternoon markers are in the table that follows a paragraph with

# Find all the tables in the document
tables = bsObj.findAll('table', {'class':'table table-responsive table-data table-align-left'})

table_body = None

# Iterate over the tables looking at the previous paragraph
for table in tables:

   p = table.find_previous('p')

   # Check for the afternoon markers text
   if p.get_text() == 'ICE BRENT AFTERNOON MARKERS':


      # Extract that table  
      table_body = table.find('tbody')


if table_body <> None:

   # Get all the rows
   rows = table_body.find_all('tr')

   # Print each row
   for row in rows:

      cols = row.find_all('td')

      print('%s %s %s' % (cols[0].text.strip(), cols[1].text.strip(), cols[2].text.strip()))


   print('No markers!')

raw_input('Press Enter to continue ...')


1 comment:

Anonymous said...

While playing is enjoyable, and also you would possibly ready to|be succesful of|have the flexibility to} win every so often with some skill, it's still a recreation of likelihood. In the top, the court ruled within the player’s favor, and the on line casino had to pay up. So, in any respected on line casino, you'll be be} paid your winnings no matter how giant lengthy as|so lengthy as} there was no malfunction and no terms and 토토사이트 situations had been violated.