@@ -0,0 +1,1540 @@
+%22%22%22%0Aa web crawler for hospital information%0A%22%22%22%0Aimport requests%0Afrom bs4 import BeautifulSoup%0Afrom pymongo import MongoClient%0A%0A%0Adef insert_item(item):%0A    %22%22%22%0A    insert an object into mongodb%0A    :param item:%0A    :return:%0A    %22%22%22%0A    client = MongoClient()%0A    db = client.living.hospital%0A    result = db.insert_one(item)%0A%0A%0Adef crawl(province_id, province_name):%0A    url = 'https://www.hqms.org.cn/usp/roster/rosterInfo.jsp?provinceId=%25s&htype=&hgrade=&hclass=&hname=' %5C%0A          '&_=1504241036511' %25 str(province_id)%0A    response = requests.get(url, timeout=20)%0A    if response.status_code == 200:%0A        json = response.json()%0A        for _ in json:%0A            _%5B'province'%5D = province_name%0A            insert_item(_)%0A        print('Insert %25s done~' %25 province_name)%0A    else:%0A        print('Error!')%0A%0A%0Adef get_province_id():%0A    province = %7B%7D%0A    response = requests.get('https://www.hqms.org.cn/usp/roster/index.jsp', timeout=10)%0A    if response.status_code == 200:%0A        soup = BeautifulSoup(response.text, 'html5lib')%0A        options = soup.find_all('select', class_='province_select')%5B0%5D.find_all('option')%0A        for i in range(1, len(options), 1):%0A            province_id = options%5Bi%5D%5B'value'%5D.strip()%0A            province_name = options%5Bi%5D.text.strip()%0A            province%5Bprovince_name%5D = province_id%0A    else:%0A        print('Error!')%0A%0A    return province%0A%0A%0Aif __name__ == '__main__':%0A    province = get_province_id()%0A    for k, v in province.items():%0A        try:%0A            crawl(v, k)%0A        except:%0A            pass%0A

Create hospital_spider.py