刚开始是在做最近地物查询,然后突然想到可以结合前后端做一个医院信息的动态展示
首先打开iserver看一个个医院的的列表
然后随便打开一个,里面有医院的id和name,可以依据名字,然后查找医院的信息(等级还有成立时间等等)
http://localhost:8090/iserver/services/data-changchun/rest/data/feature/0-27-0
发现第一个前面是不变的,就是fromindex和toindex两个在变。然后看第二个,就是最后的0-27-?,最后?这个数字变一下。Ok,然后打开pycharm,我们开始第一步,提取医院名字和id
import pymssql #引入对数据库操作模块
import requests #等会获得html
from bs4 import BeautifulSoup #
import re #
serverName = '127.0.0.1'
userName = 'sa'
passWord = 'xxxx' #密码
database='hosipital'
conn = pymssql.connect(server=serverName,user=userName,password=passWord,database=database)
cursor = conn.cursor()
creTab='CREATE TABLE inf ( id int, name varchar(100));' #创建一张表
cursor.execute(creTab)
startindex=0
count=0
for startindex in range(0,70,17):
endindex=startindex+17
baseUrl = f'http://localhost:8090/iserver/services/data-changchun/rest/data/datasources/Changchun/datasets/Hospital/features?fromIndex={startindex}&toIndex={endindex}'
r=requests.get(baseUrl)
r.encoding='utf-8'
html=r.text
soup = BeautifulSoup(html, 'html.parser')
tds=soup.find_all('td')
for td in tds:
a=td.find('a')
if a:
txt=a.get('href')
if re.match('^http.*false$',txt):
r2=requests.get(txt)
html2=r2.text
soup2=BeautifulSoup(html2,'html.parser')
div=soup2.find('div',class_='bodyDIv').find('div',id="resource