1. 程式人生 > >抓取國家的學校編碼資料

抓取國家的學校編碼資料

https://wenku.baidu.com/view/610da44658eef8c75fbfc77da26925c52cc59198.html

import requests
from bs4 import *

pageSize=20
pageIndex=1

while True:
url="http://www.csh.edu.cn/moetc/mdepartmentExtAction!toMdepartmentExtListWdOuter.action?cityId=220100000000&mdepartmentExt.type=4&mdepartmentExt.parentId=220100000000&pageSize="+str(pageSize)+"&pageIndex="+str(pageIndex)

response = requests.post(url)
soup=BeautifulSoup(response.text,'html.parser')
arr1=soup.select('.h_tdListCenter')
arr2=soup.select(".h_tdListCenter1")

for i in range(0,len(arr1)):
schoolname=arr1[i].text.replace('<td class="h_tdListCenter" nowrap="nowrap" width="30%">','').replace('</td>','').replace(" ","")
number=arr2[i].text.replace('<td class="h_tdListCenter1" nowrap="nowrap" width="30%">','').replace('</td>','').replace(" ","")
print(schoolname.strip(),end=" ")
print(number.strip())

if len(arr1)==0:
break
else:
pageIndex=pageIndex+pageSize