I am looking to alter the following code so as t run it on python2.x and beautifulsoup3.x
import requests
import BeautifulSoup
session = requests.session()
pages = []
req = session.get('webpage')
content = req.content.split("</html>")
for page in content[:-1]:
doc = BeautifulSoup.BeautifulSoup(page)
name = doc.find('table', id='table2').find('table').findAll('td')[3].text
print name
tables = doc.findAll('table', id="conn")
target_table = None
for table in tables:
try:
title = table.find('thead').find('td').text
except:
title = None
if title == 'ESME DETAILS':
target_table = table
break
if target_table:
esme_trs = target_table.find('tbody').findAll('tr')
for tr in esme_trs:
print "\t", tr.find('td').text
The problem is that
requestsis not installed in the python2.X installation, only for python3.Xrequestsisn’t standard library so it doesnt’t come installed with python, so you need to install it manually.See the instructions are on the requests website for how to install it.