I'm writing a program that gives information on actors and actresses, but I'm looking for a way to be able to get the Instagram link of the specified actor?
My code just asks for the actor or actresses name, (then it first searches for the id) then the output gives the latest five movies, the biography and the birth date and place.
(I am new to Python)
This is the code I use to get the biography and other information:
import imdb
ia = imdb.IMDb()
code = "0000093"
search_info = ia.get_person(code)
actor_results = ia.get_person_filmography(code)
print(search_info['name'],'\nDate of birth:',search_info['birth date'],'\nPlace of birth:', actor_results['data']['birth info'])
I think you can't do it in IMDbPY. However, I was able to make it work with requests and BeautifulSoup.
Here is my code:
import requests
from bs4 import BeautifulSoup
actor_code = "0001098"
url = f"https://www.imdb.com/name/nm{actor_code}/externalsites"
# get the page
page = requests.get(url)
# parse it with BeautifulSoup
soup = BeautifulSoup(page.content, "html.parser")
# get the html element which contains all social networks
social_sites_container = soup.find("ul", class_="simpleList")
#get all the individual social networks
social_sites = social_sites_container.find_all("a")
# loop through all the sites and check if it is Instagram
has_instagram = False
for site in social_sites:
if site.text == "Instagram":
print("Instagram:")
print("https://www.imdb.com" + site["href"])
has_instagram = True
if not has_instagram:
print("The actor/actress hasn't got an Instagram account")
Please let me know if you need more explaining.