#页面结构
#源代码
import requests
from bs4 import BeautifulSoup
import bs4
import re
def getHTMLText(url):
try:
kv = {‘user-agent‘:‘Mozilla/5.0‘}
r = requests.get(url, headers = kv, timeout = 30)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text
except:
return " "
def printList(ulist, html):
soup = BeautifulSoup(html, "html.parser")
title = re.findall(‘<a href.*? target="_blank".*?>(.*?)</a>‘, html)[3:13]
redu = re.findall(‘<td>(.*?)</td>‘, html)[0:10]
x = 0
print("{:^50}\t{:^5}".format(‘标题‘, ‘热度‘))
while x <= 11:
print("{:^50}\t{:^5}".format(title[x], redu[x]))
x = x + 1
def main():
uinfo = []
url = "https://tophub.today/n/Jb0vmloB1G"
html = getHTMLText(url)
printList(uinfo, html)
main()
#获取数据截图
原文:https://www.cnblogs.com/luowenfei/p/12541605.html