下面的代码输出的数据是水平的,能不能垂直的,非常感谢!
from bs4 import BeautifulSoup
import urllib2
url1 = "url"
content1 = urllib2.urlopen(url1).read()
soup = BeautifulSoup(content1,"lxml")
div = soup.find("form", {"name": "SelHorse"})
rows = div.findAll('table')[6].findAll('tr')
for row in rows:
print (row.text)
最佳答案
您可以找到所有td
标签,然后使用str.join
。
例如:
for row in rows:
if row:
print( " ".join(td.text.strip() for td in row.findAll("td") if td) )
关于python - 从下面的代码中数据输出是水平的,是否可以垂直,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50675374/