Reputation: 426
I'm trying to get every images from a website and sometimes BeautifulSoup doesn't get every src
attributes from the HTML.
Example:
data = requests.get('https://www.qmedichealth.com/')
soup = BeautifulSoup(data.text, 'html.parser')
img = soup.find_all('img')
The code is simple but I can't get the url of the slider on this website, it works for every image except the one below :
<img alt="image description" style="width: 1583px; margin-left: 0px; height: 1055.33px; margin-top: -0.166667px;" src="https://cdn.shopify.com/s/files/1/0970/0888/t/3/assets/img07.jpg">
What I actually get: <img alt="image description"/>
Any idea about this behaviour?
Upvotes: 2
Views: 1516
Reputation: 3770
check the source code you will see there is no src given..since it is getting rendered at runtime, so something like selenium would be useful
from bs4 import BeautifulSoup
from selenium import webdriver
browser = webdriver.Chrome('path to chrome driver')
download chrome driver here
http://chromedriver.chromium.org/downloads
browser.get('https://www.qmedichealth.com/')
data = BeautifulSoup(browser.page_source)
#All the Src
for src in data.find_all('img'):
print(src['src'])
Upvotes: 3