Reputation: 73
I am very new and attempting to learn how to scrape tables. I have the following code, but can not get the two variables to print on the same line; they print on separate lines. What am I missing?
from lxml import html
from bs4 import BeautifulSoup
import requests
url = "http://www.columbia.edu/~fdc/sample.html"
r = requests.get(url)
soup = BeautifulSoup(r.content)
tables = soup.findAll('table')
for table in tables:
Second_row_first_column = table.findAll('tr')[1].findAll('td')[0].text
Second_row_second_column = table.findAll('tr')[1].findAll('td')[1].text
print Second_row_first_column + Second_row_second_column
Upvotes: 4
Views: 475
Reputation: 83
I think you should use this :
Second_row_first_column = table.findAll('tr')[1].findAll('td')[0].text.rstrip('\n') + "\t"
Upvotes: 0