← Back to Home

How to Extract Comment Count from Yahoo News Page Title

Updated January 14, 2026
comment countpage titleregexjapanese

Extracting Comment Count from Page Title

Yahoo News comments page shows total comment count in the page title.

Page Title Format

(123)件のコメント - Yahoo!ニュース

Pattern: (NUMBER)件のコメント

Extraction Method

const commentData = await page.evaluate(() => {
  let totalComments = 0;
  const titleMatch = document.title.match(/(\d+)件のコメント/);

  if (titleMatch) {
    totalComments = parseInt(titleMatch[1], 10);
  }

  return { totalComments };
});

Regex Breakdown

Complete Example

function extractCommentCount(pageTitle: string): number {
  const match = pageTitle.match(/(\d+)件のコメント/);
  return match ? parseInt(match[1], 10) : 0;
}

// Usage
const totalComments = extractCommentCount(document.title);
console.log(totalComments); // 123

Notes