我是一个新手,正在尝试学习如何抓取表格数据。我有以下代码,但无法将两个变量打印在同一行上;它们会分别打印在不同的行上。我错过了什么吗?
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
table.findAll('tr')[1].findAll('td')
存储在一个变量中,然后分别使用my_var[0].text
和my_var[1].text
。 - sshashank124