I have now started working on Web Scraping with python, and I want to scrape the image from this link. And this is the screenshot of "Inspect". This is the code I tried, as it involves JavaScript.
import bs4 as bs
import sys
import urllib.request
from PyQt5.QtWebEngineWidgets import QWebEnginePage
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl
class Page(QWebEnginePage):
def __init__(self, url):
self.app = QApplication(sys.argv)
QWebEnginePage.__init__(self)
self.html = ''
self.loadFinished.connect(self._on_load_finished)
self.load(QUrl(url))
self.app.exec_()
def _on_load_finished(self):
self.html = self.toHtml(self.Callable)
print('Load finished')
def Callable(self, html_str):
self.html = html_str
self.app.quit()
def main():
page = Page('https://www.imdb.com/name/nm0005683/mediaviewer/rm2073384192')
soup = bs.BeautifulSoup(page.html, 'html.parser')
imagetag = soup.find('div', id='photo-container')
print (imagetag)
if __name__ == '__main__': main()
This code is actually from here and I altered just the link
And the error I'm getting
js: Uncaught TypeError: Cannot read property 'x' of undefined
Load finished
<div id="photo-container"></div>
I do not know what actually the error is, the contents of isn't showing up I did try googling the error but couldn't find anything that could help this situation. Also, if I should try any other method to scrape the image instead of this, I'm open to those suggestions too.
PS: I'm also new to StackOverFlow, so if anything here is not against rules, I can edit the question as required.