DIYgod/RSSHub · error · Error

无法获取最新的 year 和 issue

Error message

无法获取最新的 year 和 issue

What it means

社会学杂志 (shxyj.ajcass.com) route scrapes the homepage to discover the latest year/issue from a `p.hod.pop` element via the regex /(\d{4}) Vol\.(\d+):/. If neither the selector nor the regex matches (markup changed, or no issue line present), it throws a generic `Error('无法获取最新的 year 和 issue')`.

Solutions

  1. Supply explicit year and issue in the path so the homepage scrape is bypassed entirely.
  2. If you maintain the route, inspect https://shxyj.ajcass.com/ and update the selector ('p.hod.pop') and/or the regex.
  3. Retry later for transient homepage changes (e.g. a holiday banner).

Example fix

// before — relies on homepage scrape, throws when markup changes
if (match) { year = match[1]; issue = match[2]; }
else { throw new Error('无法获取最新的 year 和 issue'); }
// after — tolerate format drift by trying alternate selectors
const m = latestIssueText.match(/(\d{4})\s*Vol\.?\s*(\d+)/) ?? $('a:contains("Vol")').first().text().match(/(\d{4})\/?(\d+)/);
if (!m) throw new Error('无法获取最新的 year 和 issue');
// OR call with explicit params: /ajcass/shxyj/2024/5
Defensive patterns

Strategy: fallback

Validate before calling

// If you can supply explicit values, bypass the homepage scrape entirely:
function explicitShxyjArgs(year, issue) {
  return /^\d{4}$/.test(String(year)) && /^\d+$/.test(String(issue));
}

Type guard

function isExplicitIssue(year, issue): boolean {
  return /^\d{4}$/.test(String(year ?? '')) && /^\d+$/.test(String(issue ?? ''));
}

Try / catch

let year = ctxYear, issue = ctxIssue;
if (!year || !issue) {
  try {
    const $ = load((await got('https://shxyj.ajcass.com/')).body);
    const m = $('p.hod.pop').first().text().match(/(\d{4})\s*Vol\.?\s*(\d+)/);
    if (!m) throw new Error('无法获取最新的 year 和 issue');
    [year, issue] = [m[1], m[2]];
  } catch (e) {
    // fallback: try an alternate selector or a known-good recent issue
    const m2 = $('a:contains("Vol")').first().text().match(/(\d{4})/);
    if (!m2) throw e;
    year = m2[1]; issue = '1';
  }
}

Prevention

When it happens

Trigger: Calling /ajcass/shxyj without explicit year/issue params when the homepage markup has changed — selector `p.hod.pop` absent, or text no longer matches 'YYYY Vol.N:'.

Common situations: Site redesign renamed the CSS class; the homepage is temporarily showing a special-issue banner without the expected text format; the journal changed its issue-naming scheme.

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/61cc4b04c4f10da8. Report an issue: GitHub.

Appendix: source

Thrown at lib/routes/ajcass/shxyj.ts:38

    name: '社会学研究',
    maintainers: ['CNYoki'],
    handler,
};

async function handler(ctx) {
    let { year, issue } = ctx.req.param();

    if (!year) {
        const response = await got('https://shxyj.ajcass.com/');
        const $ = load(response.body);
        const latestIssueText = $('p.hod.pop').first().text();

        const match = latestIssueText.match(/(\d{4}) Vol\.(\d+):/);
        if (match) {
            year = match[1];
            issue = match[2];
        } else {
            throw new Error('无法获取最新的 year 和 issue');
        }
    }

    const url = `https://shxyj.ajcass.com/Magazine/?Year=${year}&Issue=${issue}`;
    const response = await got(url);
    const $ = load(response.body);

    const items = $('#tab tr')
        .toArray()
        .map((item) => {
            const $item = $(item);
            const articleTitle = $item.find('a').first().text().trim();
            const articleLink = $item.find('a').first().attr('href');
            const summary = $item.find('li').eq(1).text().replace('[摘要]', '').trim();
            const authors = $item.find('li').eq(2).text().replace('作者:', '').trim();
            const pubDate = parseDate(`${year}-${Number.parseInt(issue) * 2}`);

            if (articleTitle && articleLink) {

View on GitHub (pinned to bed535e087)