For this simple BeautifulSoup experiment, I am trying to scrape some simple data from an IMDB page https://www.imdb.com/title/tt7069210/
The problem is I am unable to get the elements with class rec_item
. I have tried many selectors to get the hold of it, but each time it is giving back a blank list.
Now, why I think it is strange is:
- The elements with
rec_item
are not inside any iFrame. - The elements can be seen by doing
view page source
on browser. Therefore, as per my understanding, they are NOT loaded by javascript after page load.
Here is the repl.it link of the code
Question: Can anyone please help me understand why the list of rec_item
is blank?
Additional Information
Here is the code,
from bs4 import BeautifulSoup
import requests
def extract(url):
res = requests.get(url)
bsoup = BeautifulSoup(res.text, 'html.parser')
the_title = bsoup.select('meta[name="title"]')[0].attrs['content']
print('Title: ' + the_title) # This works fine
long_text = bsoup.select('#titleStoryLine .inline.canwrap span')[0].string.strip()
print('Description: ' + long_text) # this too works fine
similar_movies = bsoup.select('.rec_item')
print(similar_movies) # blank array :(
extract('https://www.imdb.com/title/tt7069210/')