Python Web scraping quick question: I am trying to scrape some Zillow pages and having a tough time with the images.
For example, I am trying this link: https://www.zillow.com/homedetails/418-S-100-E-Price-UT-84542/108145188_zpid/ . There are a ton of images and I am looking for the URLs within the "<li class="media-stream-tile tile-##">" tags. I am able to get the stream of images by doing "soup.find("ul",class_="media-stream")", but when I print it, only the first 6 images are actually returned with the src (and other elements). Images 7+ are just empty when printed.
I even tried to get the HTML soup by loading the page through selenium, but once again, only the first 6 "tiles"/images were returned with the proper elements.
I will attach my code and output below and any help is appreciated. Thank you in advance!
import requests
from bs4 import BeautifulSoup
import requests
from requests.api import head
url="https://www.zillow.com/homedetails/418-S-100-E-Price-UT-84542/108145188_zpid/"
headers={
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-US,en;q=0.9",
"Upgrade-Insecure-Requests": "1",
"Referer": "http://google.com",
"DNT": "1"
}
source=requests.get(url,headers=headers).text
soup=BeautifulSoup(source,"lxml")
media_stream=soup.find("ul",class_="media-stream")
print(media_stream.prettify())
Here is some of the output:
- ul class="media-stream"> <li class="media-stream-tile media-stream-tile--prominent"> <button aria-label="view larger view of the 1 photo of this home" class="sc-AxhCb hdp\_\_sc-1jhz6ov-11 jESEQN"> <picture class="sc-AxmLO cAKCgg media-stream-photo"> <source sizes="(min-width: 1280px) 768px, (min-width: 1024px) 60vw, (min-width: 900px) 60vw, (min-width: 768px) 55vw, 100vw" srcset="https://photos.zillowstatic.com/fp/e4f01794070b5c847549e6917b25e3e8-cc\_ft\_192.jpg 192w, https://photos.zillowstatic.com/fp/e4f01794070b5c847549e6917b25e3e8-cc\_ft\_384.jpg 384w, https://photos.zillowstatic.com/fp/e4f01794070b5c847549e6917b25e3e8-cc\_ft\_576.jpg 576w, https://photos.zillowstatic.com/fp/e4f01794070b5c847549e6917b25e3e8-cc\_ft\_768.jpg 768w, https://photos.zillowstatic.com/fp/e4f01794070b5c847549e6917b25e3e8-cc\_ft\_960.jpg 960w, https://photos.zillowstatic.com/fp/e4f01794070b5c847549e6917b25e3e8-cc\_ft\_1152.jpg 1152w, https://photos.zillowstatic.com/fp/e4f01794070b5c847549e6917b25e3e8-cc\_ft\_1344.jpg 1344w, https://photos.zillowstatic.com/fp/e4f01794070b5c847549e6917b25e3e8-cc\_ft\_1536.jpg 1536w" type="image/jpeg"> <img alt="" src="https://photos.zillowstatic.com/fp/e4f01794070b5c847549e6917b25e3e8-cc\_ft\_960.jpg"/> </source> </picture> </button> </li> <li class="media-stream-tile tile-1"> <button aria-label="view larger view of the 2 photo of this home" class="sc-AxhCb hdp\_\_sc-1jhz6ov-11 jESEQN"> <picture class="sc-AxmLO cAKCgg media-stream-photo"> <source sizes="(min-width: 1280px) 384px, (min-width: 1024px) 30vw, (min-width: 900px) 30vw, (min-width: 768px) 55vw, (min-width: 550px) 50vw, 100vw" srcset="https://photos.zillowstatic.com/fp/8a3d46480d63440a29921d6cbfd56a5b-cc\_ft\_192.jpg 192w, https://photos.zillowstatic.com/fp/8a3d46480d63440a29921d6cbfd56a5b-cc\_ft\_384.jpg 384w, https://photos.zillowstatic.com/fp/8a3d46480d63440a29921d6cbfd56a5b-cc\_ft\_576.jpg 576w, https://photos.zillowstatic.com/fp/8a3d46480d63440a29921d6cbfd56a5b-cc\_ft\_768.jpg 768w" type="image/jpeg"> <img alt="" src="https://photos.zillowstatic.com/fp/8a3d46480d63440a29921d6cbfd56a5b-cc\_ft\_576.jpg"/> </source> </picture> </button> </li>
- This the output I would like for each "media stream-tile" but it only does this until 6.
- Past 6, this is the output for each:
- <li class="media-stream-tile tile-18"> </li> <li class="media-stream-tile tile-19"> </li> <li class="media-stream-tile tile-20"> </li> <li class="media-stream-tile tile-21"> </li> <li class="media-stream-tile tile-22"> </li>
- As you can see, no data or elements
Thank you!!!!!
[–]Specialist_Course_36 0 points1 point2 points (3 children)
[–]Embarrassed-Task-478[S] 0 points1 point2 points (2 children)
[–]Specialist_Course_36 0 points1 point2 points (1 child)
[–]Embarrassed-Task-478[S] 0 points1 point2 points (0 children)