Вам нужно найти тег span и использовать атрибут data-content
, а затем использовать регулярное выражение для получения номера телефона.
import re
import requests
from bs4 import BeautifulSoup
raw = requests.get('https://www.yellowpages.my/listing/results.php?keyword=boutique&where=selangor&screen=2').text
raw = raw.replace("</br>", "")
soup = BeautifulSoup(raw, 'html.parser')
name = soup.find_all('div', {'class' :'cbp-vm-companytext'})
phone = [re.findall('\>.*?<',d.find('span')['data-content'])[0][1:][:-1] for d in soup.find_all('div',{'class':'cbp-vm-cta'})]
addresses = [x.text.strip().split("\r\n")[-1].strip() for x in soup.find_all("div", class_='cbp-vm-address')]
print(phone)
#print(addresses)
#print(name)
Выход :
['03-8922 0982', '018-651 9855', '012-931 2419', '03-5523 0664', '03-6057 1190', '03-6150 1314', '03-6150 4588', '03-40650044', '016-292 5956', '03-3250 6633', '03-7728 5339', '03-8063 6788']
Обновление
import re
import requests
from bs4 import BeautifulSoup
raw = requests.get('https://www.yellowpages.my/listing/results.php?keyword=boutique&where=selangor&screen=3').text
raw = raw.replace("</br>", "")
soup = BeautifulSoup(raw, 'html.parser')
phone = [re.findall('\>.*?<',d.find('span',attrs={"data-content": True})['data-content'])[0][1:][:-1] for d in soup.find_all('div',{'class':'cbp-vm-cta'})]
print(phone)
ОБНОВЛЕНИЕ Используйте try, кроме блока
import re
import requests
from bs4 import BeautifulSoup
raw = requests.get('https://www.yellowpages.my/listing/results.php?keyword=boutique&where=selangor&screen=1').text
raw = raw.replace("</br>", "")
soup = BeautifulSoup(raw, 'html.parser')
try:
phone = [re.findall('\>.*?<',d.find('span',attrs={"data-content": True})['data-content'])[0][1:][:-1] for d in soup.find_all('div',{'class':'cbp-vm-cta'})]
print(phone)
except:
print("None")