Вам не нужно использовать Selenium или даже BeautifulSoup.Если вы проверяете сетевые запросы от Developer Tools (F12) > Network
, вы можете видеть, что данные выбираются с использованием XHR-запроса
Вы можете сделать этот запрос самостоятельно и использоватьответ JSON в любом случае.
POST https://mortgageapi.zillow.com/getRegisteredLender?partnerId=RD-CZMBMCZ
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0
Referer: https://www.zillow.com/lender-profile/DougShoemaker/
Content-Type: application/json
{
"fields": [
"aboutMe",
"address",
"cellPhone",
# ... other fields
"website"
],
"lenderRef": {
"screenName": "DougShoemaker"
}
}
Теперь с библиотекой requests
вы можете попробовать:
import requests
if __name__ == '__main__':
payload = {
"fields": [
"screenName",
"cellPhone",
"officePhone",
"title",
],
"lenderRef": {
"screenName": "DougShoemaker"
}
}
res = requests.post('https://mortgageapi.zillow.com/getRegisteredLender?partnerId=RD-CZMBMCZ',
json=payload)
res.raise_for_status()
data = res.json()
cellphone, office_phone = data['lender']['cellPhone'], data['lender']['officePhone']
cellphone_num = '({areaCode}) {prefix}-{number}'.format(**cellphone)
office_phone_num = '({areaCode}) {prefix}-{number}'.format(**office_phone)
print(office_phone_num, cellphone_num)
, которая печатает:
(618) 619-4120 (618) 795-0790