I searched a lot on SO, but most of the answers were not able to solve my problem:
What I am trying to scrape:
- I have a link. The link redirects to a dynamic website.
- I want to get the number of videos and number of images residing on this link.
- I want to do it using bs4, Selenium and Python.
What problem I am facing:
- When I check the "inspect element" and do a simple Ctrl+F to find the videos tags. I can see the right amount of videos. But, when I open the "view source" of the same page, I can see only 1 video tag.
Furthermore, when I try to scrape, I am able to retrieve only 1 video. I do not know why the other videos tags are not being detected by bs4. I am assuming this has something to do with Javascript loaded pages. But, even when I use the below code, with Selenium, I am still not able to get the correct number of videos and images
This is the code I have tried:
driver = webdriver.Chrome()
driver.get("https://www.kickstarter.com/projects/evolutionwear/fast-solar-charging-that-fits-in-your-pocket/?ref=kicktraq")
res = driver.execute_script('return document.documentElement.outerHTML')
soup = BeautifulSoup(res, 'html.parser')
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
c=1
for vidL in soup.find_all("div", {'class': 'play_button_container absolute-center has_played_hide'}):
print(vidL)
print(c)
c+=1