|
| 1 | +import { Route } from '@/types'; |
| 2 | +import got from '@/utils/got'; |
| 3 | +import { load } from 'cheerio'; |
| 4 | +import { parseDate } from '@/utils/parse-date'; |
| 5 | + |
| 6 | +export const route: Route = { |
| 7 | + path: '/journals/society/current', |
| 8 | + categories: ['journal'], |
| 9 | + example: '/journals/society/current', |
| 10 | + features: { |
| 11 | + requireConfig: false, |
| 12 | + requirePuppeteer: false, |
| 13 | + antiCrawler: false, |
| 14 | + supportBT: false, |
| 15 | + supportPodcast: false, |
| 16 | + supportScihub: false, |
| 17 | + }, |
| 18 | + name: '《社会》杂志当期目录', |
| 19 | + maintainers: ['CNYoki'], |
| 20 | + handler, |
| 21 | +}; |
| 22 | + |
| 23 | +async function handler() { |
| 24 | + const url = 'https://www.society.shu.edu.cn/CN/1004-8804/current.shtml'; |
| 25 | + const response = await got(url); |
| 26 | + const $ = load(response.body); |
| 27 | + |
| 28 | + // 提取刊出日期 |
| 29 | + const pubDateText = $('.dqtab .njq') |
| 30 | + .text() |
| 31 | + .match(/刊出日期:(\d{4}-\d{2}-\d{2})/); |
| 32 | + const pubDate = pubDateText ? parseDate(pubDateText[1]) : null; |
| 33 | + |
| 34 | + const items = $('.wenzhanglanmu') |
| 35 | + .nextAll('.noselectrow') |
| 36 | + .toArray() |
| 37 | + .map((item) => { |
| 38 | + const $item = $(item); |
| 39 | + const titles = $item.find('.biaoti').text().trim(); |
| 40 | + const links = $item.find('.biaoti').attr('href'); |
| 41 | + const authors = $item.find('.zuozhe').text().trim(); |
| 42 | + const abstract = $item.find('div[id^="Abstract"]').text().trim(); |
| 43 | + |
| 44 | + if (titles && links) { |
| 45 | + return { |
| 46 | + title: titles, |
| 47 | + link: links, |
| 48 | + description: abstract, |
| 49 | + author: authors, |
| 50 | + pubDate, |
| 51 | + }; |
| 52 | + } |
| 53 | + return null; |
| 54 | + }) |
| 55 | + .filter((item) => item !== null); |
| 56 | + |
| 57 | + return { |
| 58 | + title: '《社会》当期目录', |
| 59 | + link: url, |
| 60 | + item: items, |
| 61 | + }; |
| 62 | +} |
0 commit comments