马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import requests
from bs4 import BeautifulSoup
import bs4
def getHTMLText(url):
try:
r = requests.get(url)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text
except:
return ""
def fillRankInformation(rinfo, html):
soup = BeautifulSoup(html, "html.parser")
for tr in soup.find('tbody').children:
if isinstance(tr, bs4.element.Tag):
tds = tr('td')
rinfo.append([tds[0].string, tds[1].string,tds[2].string, tds[3].string, tds[4].string, tds[5].string, tds[6].string, tds[7].string, tds[8].string])
def printRank(rinfo, num):
for i in range(num):
r=rinfo[i]
print("{:^6}\t{:^6}\t{:^10}\t{:^10}\t{:^10}\t{:^10}\t{:^10}\t{:^10}".format(r[0],r[1],r[2],r[3],r[4],r[5],r[6],r[7],r[8]))
def main():
num = 50
rlist = []
url = 'http://www.jjwxc.net/topten.php?orderstr=7&t=1'
html = getHTMLText(url)
fillRankInformation(rlist, html)
printRank(rlist, num)
main()
报错 TypeError: unsupported format string passed to NoneType.__format__
如果直接输出的话输出内容为空
为什么会这样,怎么改,求大佬讲详细一点![](static/image/smiley/ARU/aru-1x-1_039.png) ![](static/image/smiley/ARU/aru-1x-1_039.png) |