使用了三个网页ID:38635、38636、38627来测试,输出dic的结果为三个同样的字典(都对应38635),
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
url='https://db.yaozh.com/hmap?grade=%E5%85%A8%E9%83%A8&p={}&pageSize=30&province=%E5%B9%BF%E4%B8%9C%E7%9C%81&type=%E5%85%A8%E9%83%A8'
info_url_model='https://db.yaozh.com{}'
for x in ['/hmap/38625.html', '/hmap/38626.html', '/hmap/38627.html']: #test
info_url=info_url_model.format(x) #填入医院urlID
detail = requests.get(info_url, headers=headers) # 取得内容页面内容
detail.encodint = 'utf-8'
soup2 = BeautifulSoup(detail.text, 'html.parser')
a = soup2.select('.toFindImg')
for b in soup2.find_all(lambda tag: tag.name == 'span' and tag.get('class') == ['toFindImg']):
item_list.append(b.text)
for i in range(len(item_list)): #去掉空格
item_list[i] = item_list[i].replace(' ', '') #去掉空格
item_list[i] = item_list[i].replace('\n', '') #去掉换行符
dic = dict(zip(item_name, item_list)) # 生成字典
print(dic)