我有一个网站来提取信息。 例如,http://www.worldhospitaldirectory.com/alaska-native-medical-center/info/8500
我需要提取信息并保存到CSV文件中。例如,
类别:综合医院
名称:阿拉斯加原住民医疗中心
地址:4315 Diplomacy Drive
电话:(907)563-2662
城市:安克雷奇
州:阿拉斯加州
但现在的问题是我找不到这些信息。 网络代码如下:
<b>Category:</b>
General Hospitals
<br>
<b>Address:</b>
4315 Diplomacy Drive
<br>
<b>Subcontinent and Continent:</b>
North America, America
<br>
请给我一些建议或代码,以帮助我获取这些文字。
答案 0 :(得分:0)
import requests, bs4
r = requests.get('http://www.worldhospitaldirectory.com/alaska-native-medical-center/info/8500')
soup = bs4.BeautifulSoup(r.text, 'lxml')
start = soup.find('em')
for b in start.find_next_siblings('b'):
print(b.text, b.next_sibling.strip())
出:
Category: General Hospitals
Address: 4315 Diplomacy Drive
Subcontinent and Continent: North America ,
America
Country: United States
Phone (907) 563-2662
Website:
City:
State:
Email:
Latitude: 61.1827
Longitude: -149.80009
Zip Code: 99508
Contact Address: 4315 Diplomacy Dr, Anchorage, AK 99508, United States
Latitude in Degree, Minute, Second [Direction]: 61° 10' 57" N