其他分享
首页 > 其他分享> > 字体测试页面

字体测试页面

作者:互联网

import csv
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://en.wikipedia.org/wiki/Comparison_of_text_editors")
bsObj = BeautifulSoup(html)
# 主对比表格是当前页面上的第一个表格
table = bsObj.findAll("table",{"class":"wikitable"})[0]
rows = table.findAll("tr")
csvFile = open("C:/Users/Administrator/Desktop/test2.csv", 'wt', newline="", encoding='utf-8')
writer = csv.writer(csvFile)
try:
     for row in rows:
         csvRow = []
         for cell in row.findAll(['td', 'th']):
             csvRow.append(cell.get_text())
             writer.writerow(csvRow)
finally:

    csvFile.close()

标签:writer,csvFile,csvRow,字体,测试,import,table,csv,页面
来源: https://www.cnblogs.com/yeu4h3uh2/p/12918778.html