#python爬虫实战,爬取学校排名

#python爬虫实战,爬取学校排名_第1张图片

import requests
from bs4 import BeautifulSoup
import bs4
target = "http://www.zuihaodaxue.cn/zuihaodaxuepaiming2019.html"


def start_page(url,callback):
    resp = requests.get(url)
    callback(resp.content)

def printHtml(text):
    soup = BeautifulSoup(text, "html.parser")
    # print(soup)
    table = soup.find('tbody')
    list = []
    for tr in table.find_all('tr'):
        if isinstance(tr ,bs4.element.Tag):
            tds = tr('td')
            list.append([tds[0].string,tds[1].string,tds[3].string])
    print("大学排名   大学名字  分数")
    for school in list:
        print("{}     {}      {}" .format(school[0],school[1],school[2]))


start_page(target,callback=printHtml)


你可能感兴趣的:(Python爬虫)