diff --git a/thelordofporn/src/scraper.py b/thelordofporn/src/scraper.py index ef18623..f5858a4 100644 --- a/thelordofporn/src/scraper.py +++ b/thelordofporn/src/scraper.py @@ -119,25 +119,34 @@ def parse_actor_list(soup, href): for article in articles: try: # 获取演员详情 - title_tag = article.find("h3", class_="loop-item__title").find("a") - title = title_tag.text.strip() - href = title_tag["href"] + title_tag = article.find("h3", class_="loop-item__title") + title = title_tag.find("a").text.strip() if title_tag and title_tag.find("a") else "N/A" + href = title_tag.find("a")["href"] if title_tag and title_tag.find("a") else None # 获取评分 rating_tag = article.find("div", class_="loop-item__rating") rating = rating_tag.text.strip() if rating_tag else "N/A" # 获取 Rank 和 Votes - meta_tags = article.find("div", class_="loop-item__rank").find_all("span") - rank = meta_tags[0].find("b").text.strip() if meta_tags else "N/A" - votes = meta_tags[1].find("b").text.strip() if len(meta_tags) > 1 else "N/A" + rank_votes_div = article.find("div", class_="loop-item__rank") + meta_tags = rank_votes_div.find_all("span") if rank_votes_div else [] + + # 安全获取 rank 和 votes + rank = None + votes = None + if len(meta_tags) >= 1: + rank_b = meta_tags[0].find("b") + rank = rank_b.text.strip() if rank_b else "N/A" + if len(meta_tags) >= 2: + votes_b = meta_tags[1].find("b") + votes = votes_b.text.strip() if votes_b else "N/A" # 存入列表 actress_list.append({ "pornstar": title, - "rating": utils.parse_numeric(rating), - "rank": utils.parse_numeric(rank), - "votes": utils.parse_numeric(votes), + "rating": utils.parse_numeric(rating) if rating != "N/A" else None, + "rank": utils.parse_numeric(rank) if rank is not None else None, + "votes": utils.parse_numeric(votes) if votes is not None else None, "href": href })