程序跑不起来啊,那个大佬帮我看看错在哪里哦!(查过Google和百度了)
程序代码:
import requests from bs4 import BeautifulSoup import bs4 def get_html_text(url): # 获取页面信息 try: r = requests.get(url, timeou=3) r.raise_for_status() r.encoding = 'utf-8' return r.text except: return "" def fill_univlist(ulist, html): soup = BeautifulSoup(html, 'html.parser') for tr in soup.find('tbody').children: if isinstance(tr, bs4.element.Tag): # 去除所有非标签类的信息 tds = tr('td') # 查询tr标签中的td标签 ulist.append(tds[0].string, tds[1].string, tds[2].string, ) def print_univlist(ulist, num): print("{:^10}\t{:^6}\t{:^10}\t".format("排名", "学校名称", "总分")) for i in range(num): u = ulist[i] print("{:^10}\t{:^6}\t{:^10}\t".format(u[0], u[1], u[2])) def main(): url = 'http://www.' uinfo = [] html = get_html_text(url) fill_univlist(uinfo, html) print_univlist(uinfo, 20) main()
下面是报错: