This code is to search a movie from a webpage and print the first title of the search result.
from urllib.request import urlopen
import urllib
from bs4 import BeautifulSoup
import requests
import pprint
def infopelicula(nombrepelicula):
my_url='http://www.imdb.com/find?ref_=nv_sr_fn&q='+nombrepelicula+'&s=tt'
rprincipal = requests.get(my_url)
soup= BeautifulSoup(rprincipal.content, 'html.parser')
title = soup.findAll("td", class_="result_text")
for name in title:
titulo = name.parent.find("a", href=True)
print (name.text)[0]
It does work but when print the title, the Error appears. Here an example:
>>>infopelicula("Harry Potter Chamber")
Harry Potter and the Chamber of Secrets (2002)
Traceback (most recent call last):File "<pyshell#49>", line 1, in <module>
infopelicula("Harry Potter Chamber")
File "xxxx", line 14, in infopelicula print (name.text)[0]
TypeError: 'NoneType' object is not subscriptable