I am attempting to loop through multiple real estate agent websites, scraping the agents name and mobile number.
My code:
locations = ['woollahra', 'chinatown', 'bondibeach','doublebay']
for location in locations:
my_url = 'https://' + location + '.ljhooker.com.au/our-team'
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, "html.parser")
containers = page_soup.findAll("div", {"class":"team-details"})
for container in containers:
agent_name = container.findAll("div", {"class":"team-name"})
name = agent_name[0].text
phone = container.findAll("span", {"class":"phone"})
mobile = phone[0].text
print("name: " + name)
print("mobile: " + mobile)
However when I run my script, it skips the first three webpages (woollahra, chinatown, bondibeach) and only scraping the info from the last website in the list (doublebay). I am unsure why it is doing this or how make it loop through all webpages.
importstatementsmy_urlat the end? How do you expect it to repeat the code below for all instances ofmy_url?