我从标题获取文本,从HTML获取href属性。代码运行良好,我可以将其全部导入到PrettyTable中。我现在面临的问题是,我认为有些标题对表格中的一个盒子来说太大了,从而扭曲了整个PrettyTable制作。我尝试调整hrules、vrules和padding_width,但没有找到解决方案。
from bs4 import BeautifulSoup
from prettytable import PrettyTable
import urllib
r = urllib.urlopen('http://www.genome.jp/kegg-bin/show_pathway?map=hsa05215&show_description=show').read()
soup = BeautifulSoup((r), "lxml")
links = [area['href'] for area in soup.find_all('area', href=True)]
titles = [area['title'] for area in soup.find_all('area', title=True)]
k = PrettyTable()
k.field_names = ["ID", "Active Compound", "Link"]
c = 1
for i in range(len(titles)):
k.add_row([c, titles[i], links[i]])
c += 1
print(k)我希望整个表格显示为:
print (k.get_string(start=0, end=25))如果PrettyTable做不到的话。有没有其他推荐的模块可以实现这一点?
https://stackoverflow.com/questions/38278485
复制相似问题