Вы можете использовать такой метод, как селен, чтобы разрешить рендеринг контента в javascript.Затем вы можете получить page_source, чтобы продолжить работу со своим сценарием.Я намеренно сохранил ваш сценарий и добавил только новые строки для ожидания содержимого.
Вы можете запустить селен без головы или переключиться на использование HTMLSession.
from bs4 import BeautifulSoup as bs
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
d = webdriver.Chrome()
d.get('https://rwbj.com.au/find-an-agent.html')
WebDriverWait(d,10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "h3")))
soup = bs(d.page_source, 'lxml')
d.quit()
data = soup.find_all("div",{"class":"fluidgrid-cell fluidgrid-cell-2"})
records = []
name =[]
phone =[]
email=[]
title=[]
location=[]
for item in data:
name = item.find('h3',class_='heading').text.strip()
phone = item.find('a',class_='text text-link text-small').text.strip()
email = item.find('a',class_='text text-link text-small')['href']
title = item.find('div',class_='text text-small').text.strip()
location = item.find('div',class_='text text-small').text.strip()
records.append({'Names': name, 'Title': title, 'Email': email, 'Phone': phone, 'Location': location})
df = pd.DataFrame(records,columns=['Names','Title','Phone','Email','Location'])
print(df)
Iможет рассмотреть, в зависимости от того, присутствуют ли все предметы для каждого человека, что-то вроде:
from bs4 import BeautifulSoup as bs
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
import pandas as pd
options = Options()
options.headless = True
d = webdriver.Chrome(options = options)
d.get('https://rwbj.com.au/find-an-agent.html')
WebDriverWait(d,10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "h3")))
soup = bs(d.page_source, 'lxml')
d.quit()
names = [item.text for item in soup.select('h3')]
titles = [item.text for item in soup.select('h3 ~ div:nth-of-type(1)')]
tels = [item.text for item in soup.select('h3 + a')]
emails = [item['href'] for item in soup.select('h3 ~ a:nth-of-type(2)')]
locations = [item.text for item in soup.select('h3 ~ div:nth-of-type(2)')]
records = list(zip(names, titles, tels, emails, positions))
df = pd.DataFrame(records,columns=['Names','Title','Phone','Email','Location'])
print(df)