You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于词数与字符边界从谷歌抓取文本中提取合规人名

Extracting Valid Person Names from Scraped Text with Custom Boundaries

Hey there! Let's figure out how to extract that name correctly based on your rules. You've got a scraped string from Google:

Raveena Tandon (born 26 October 1974) is an Indian actress who works in Hindi films.

And you need to verify the opening text is a real name, using boundaries: the name ends at the first ( (matching Wikipedia's person entry format) OR caps at 4 words max. Here's a straightforward way to do this:

Core Approach

We'll combine two key checks to nail this:

  • Prioritize the ( boundary first, since that's a strong signal of a Wikipedia-style name+birth detail structure
  • Fall back to a 4-word limit to avoid pulling in descriptive text if the ( is missing or misplaced

Example Implementation (Python)

Python is a common tool for web scraping tasks, so here's a quick script that does exactly what you need:

# Your scraped text
scraped_string = "Raveena Tandon (born 26 October 1974) is an Indian actress who works in Hindi films."

# Step 1: Grab everything before the first opening parenthesis, then clean up whitespace
pre_parenthesis_text = scraped_string.split('(')[0].strip()

# Step 2: Split into words and take up to the first 4 (in case there's no parenthesis)
extracted_name = ' '.join(pre_parenthesis_text.split()[:4])

# Output the result
print(extracted_name)  # Prints: Raveena Tandon

How This Works

  • Splitting on (: This directly targets the pattern you referenced (name followed immediately by (age/birth info)). The split('(')[0] grabs all text before the first (, and strip() removes any accidental trailing spaces.
  • Capping at 4 words: Even if your scraped text didn't have a ( (e.g., a messy entry like Jane Marie Lee Davis is an actress...), this ensures you only take up to 4 words—sticking to your rule that names don't exceed 4 words.
  • Edge case coverage: If a name has exactly 4 words before a (, like Robert John Smith Jr (born...), the script will correctly extract the full 4-word name.

内容的提问来源于stack exchange,提问作者srb633

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 09:22:38