题目连接php
import requests
from bs4 import BeautifulSoup
r = requests.get('http://ctf5.shiyanbar.com/jia/index.php')
r.encoding = r.apparent_encoding
soup = BeautifulSoup(r.text,'html.parser')
a = soup.find_all('div',{"name":"my_expr"})
只有一个p标签
因此能够直接这么使用直接匹配phtml
b=soup.p.div.get_text()
题目地址python
解析出排名和大学名称便可app
from bs4 import BeautifulSoup
import requests
r = requests.get('http://www.zuihaodaxue.cn/zuihaodaxuepaiming2019.html')
r.encoding = r.apparent_encoding
attr = {"class":"table table-small-font table-bordered table-striped"}
soup = BeautifulSoup(r.text,'html.parser')
a = soup.find('table',attr)
a = a.find_all('tr',{"class":"alt"})
result = '排名,大学\n'
for i in a:
result += i('td')[0].text +','+i.div.text+'\n'
with open('rank.csv','w') as f:
f.write(result)