这是我的代码。如何从网页返回的数据中提取手机号码?
from bs4 import BeautifulSoup
import requests
r = requests.get("https://www.medindia.net/patients/doctor_search/dr-amiya-obstetrics-and-gynaecology-north-lakhimpur-assam-231775-1.htm")
soup = BeautifulSoup(r.text,'lxml')
data= soup.find('div',class_='col-xs-12')
h3 = data.find('h3')
print h3.text
p = data.find('p')
print p.text
r = data.find('span')
print r.text
答案 0 :(得分:0)
您可以尝试使用findAll('p')而不是仅仅使用find('p')。
from bs4 import BeautifulSoup
import requests
r = requests.get("https://www.medindia.net/patients/doctor_search/dr-amiya-obstetrics-and-gynaecology-north-lakhimpur-assam-231775-1.htm")
soup = BeautifulSoup(r.text,'lxml')
data= soup.find('div',class_='col-xs-12')
h3 = data.find('h3')
print(h3.text)
p = data.findAll('p')
for pdata in p:
print(pdata.text)
r = data.find('span')
print(r.text)
输出:
Dr. Amiya
ward no 12, k b road , north lakhimpur - 787001, assam
Phone : 91-3752-9435487Email : damircentre@gmail.com
damircentre@gmail.com