test("React With SCSS Style", () => { //expect.assertions(1); return get("/react/withStyle").then(data => { const $ = cheerio.load(data); expect( $('head [rel="stylesheet"]') .attr("href") .endsWith("bundle.css") ).toBe(true); }); });
async crawlList(listURL: string, crawlerDto: CrawlerDto) { if (crawlerDto.from === CrawlerArticleFrom.ArticleFromZhihu) { return await this.crawlZhihuList(listURL, crawlerDto); } if (crawlerDto.from === CrawlerArticleFrom.ArticleFromSegmentJuejin) { return await this.crawlJuejinList(listURL, crawlerDto); } const pageResult = await axios.get(listURL); const $ = cheerio.load(pageResult.data); const articleItems = $(crawlerDto.itemSelector); const articleURLArr: string[] = []; if (articleItems && articleItems.length) { // tslint:disable-next-line: prefer-for-of for (let i = 0; i < articleItems.length; i++) { const articleLink = $(articleItems[i]).find(crawlerDto.itemTitleSelector); let href: string = articleLink.attr('href') || ''; href = href.trim(); if (href) { href = url.resolve(listURL, href); articleURLArr.push(href); } } } await bluebird.map(articleURLArr, (articleURL) => { return this.crawlPage(articleURL, crawlerDto); }, { concurrency: 10 }); }
let imgURL = img.attr('src') || img.attr('_src'); imgURL = imgURL || img.attr('data-original-src'); // 简书 imgURL = img.attr('data-actualsrc'); || imgURL.indexOf('segmentfault.com') > 0) && img.attr('data-src')) { imgURL = img.attr('data-src'); imgURL = imgURL || img.attr('data-src'); if (imgURL) { imgURL = url.resolve(pageURL, imgURL); }, { concurrency: 20 }); uploadImgURLArr.forEach((newImgURL, i) => { $(imgs[i]).attr('src', newImgURL); }); let linkURL = link.attr('href'); if (linkURL) { linkURL = url.resolve(pageURL, linkURL); link.attr('href', linkURL);
test("React With Custom Meta Charset", () => { //expect.assertions(1); return get("/react/withcustomcharset").then(data => { const $ = cheerio.load(data); expect($("head [charset]").attr("charset")).toBe("ISO-8859-1"); }); });
const tmp = { title: $(this).text(), id: regx($(this).attr('href'))
.children('.cont-list-main') .find('img') .attr('data-src')
.split('Tags:')[1] $('#picture p img').each(function () { links.push($(this).attr('src')) }) console.log(links)
const href = $(this) .find('.read-more') .attr('href') const date = $(this) .find('.entry-date')
test("React With Default Meta Charset", () => { //expect.assertions(1); return get("/react/withhelmet").then(data => { const $ = cheerio.load(data); expect($("head [charset]").attr("charset")).toBe("utf-8"); }); });
test("HTML With SCSS Style", () => { //expect.assertions(1); return get("/html/withScriptAndStyle").then(data => { const $ = cheerio.load(data); expect( $('[rel="stylesheet"]') .attr("href") .endsWith(".css") ).toBe(true); }); });
test("HTML With Script", () => { //expect.assertions(1); return get("/html/withScriptAndStyle").then(data => { const $ = cheerio.load(data); expect( $("script") .attr("src") .endsWith(".js") ).toBe(true); }); });
test(".MDX File (With Syntax Highlight)", () => { //expect.assertions(1); return get("/mdx/syntaxhighlight").then(data => { const $ = cheerio.load(data); expect($("pre").attr("class")).toBe("prism-code language-js"); }); });