The second style tag contains css code in which the sequence of the icon-xx properties defines which number the property matches with. This is used to load an image with this number on the webpage, so there are no numbers to scrape. The solution is to 1) map the icon-xx properties to numbers based on their sequence in the css string; 2) find the phone number spans in the html body and retrieve the matching numbers:
import requests
from bs4 import BeautifulSoup
url = 'https://www.justdial.com/Pune/Sunrise-Enterprises-Budhwar-Peth/020PXX20-XX20-130817131104-Z3I2_BZDET?xid=UHVuZSBFbGVjdHJvbmljIENvbXBvbmVudCBEZWFsZXJz'
r = requests.get(url, headers={'User-Agent' : "Mozilla/5.0 (Windows NT 6.1; Win64; x64)"})
soup = BeautifulSoup(r.text, "html.parser")
text = soup.find_all('style', {"type": "text/css"}, text=True)[1]
data = text.contents[0].split('smoothing:grayscale}', 1)[1].split('
')[0]
icon_items = [i.split(':')[0] for i in data.split('.') if len(i)>0]
items = ['0','1','2','3','4','5','6','7','8','9','+','-',')','(']
full_list = dict(zip(icon_items, items))
phone_numbers = soup.find_all('span',{'class':'telnowpr'})
for i in phone_numbers:
numbers = i.find_all('span')
number = [full_list[y.attrs['class'][1]] for y in numbers]
print("phone number: " + ''.join([str(elem) for elem in number]) )
Result:
phone number: 07947197693
phone number: 07947197693
phone number: 07947197693
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…