0

我正在编写一个提供有关演员和女演员信息的程序,但我正在寻找一种能够获取指定演员的 Instagram 链接的方法?

我的代码只询问演员姓名,(然后它首先搜索 id)然后输出给出最新的五部电影、传记以及出生日期和地点。

(我是 Python 新手)

这是我用来获取传记和其他信息的代码:

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'])
4

1 回答 1

0

我认为你不能在 IMDbPY 中做到这一点。但是,我能够使其与 requests 和 BeautifulSoup 一起使用。

这是我的代码:

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")

如果您需要更多解释,请告诉我。

于 2020-06-18T14:07:56.140 回答