我如何使用网络抓取或 IMDbPY 来获取演员 Instagram 帐户的 link?

How can I use web scraping or IMDbPY to be able to get the link of an actor's Instagram account?

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

我的代码只询问男演员或女演员的名字,(然后它首先搜索 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'])

我认为你不能在 IMDbPY 中做到这一点。但是,我能够让它与请求和 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")

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