本文整理汇总了TypeScript中cheerio.load函数的典型用法代码示例。如果您正苦于以下问题:TypeScript load函数的具体用法?TypeScript load怎么用?TypeScript load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: getNewsContent
public async getNewsContent(newsURL: string): Promise<NewsContent> {
try {
await delay(5000);
const response = await request({
uri: newsURL,
headers: commonHeaders,
encoding: null,
});
let $ = cheerio.load(response);
$('script').remove();
const encodedResponse = iconv.decode(response, $('meta[charset]').attr('charset')).toString();
$ = cheerio.load(encodedResponse);
const newsTitle = $('meta[property=\'og:title\']').attr('content');
const newsContent = $('#articeBody, #newsEndContents, #articleBodyContents');
return {
title: newsTitle,
content: newsContent.html(),
plain_text: newsContent.text(),
press: $('.press_logo img, #pressLogo img').attr('alt'),
link: newsURL,
};
} catch (err) {
logger.error(err);
}
}
开发者ID:endlessdev,项目名称:PortalRank,代码行数:28,代码来源:naver-parser.ts
示例2: parseSeiten
export async function parseSeiten( url: string | URL ) {
const html = await request( url );
const results: Seite[] = [];
const $ = load( html );
if ( $( '.adbbody table' ).length ) {
results.push( {
selektion: 'Alle',
institutionen: parseInstitutionen( $ )
} );
} else if ( $( '.adbbody ul.adbul1 li' ).length ) {
const selektion = parseSelektion( $ );
for ( let { url, text } of selektion ) {
const html = await request( baseURL( url ) );
const $ = load( html );
results.push( {
selektion: text,
institutionen: parseInstitutionen( $ )
} );
}
}
return results;
}
开发者ID:maxwellium,项目名称:german-courts,代码行数:26,代码来源:seite.ts
示例3: get
public async get(): Promise<void> {
const baseUrl = 'https://www.jw.org';
const url = `${baseUrl}/cmn-hans/出版物/音乐/高声欢唱/`;
const urlT = `${baseUrl}/cmn-hant/出版物/音樂/高聲歡唱/`;
const downloader = new GenericDownloader();
const response = await downloader.download(url);
const responseT = await downloader.download(urlT);
const $list = cheerio.load(response);
const $listT = cheerio.load(responseT);
const xpath = '.musicList .musicFileContainer .fileTitle a';
const links = $list(xpath).toArray();
const linksT = $listT(xpath).toArray();
let song = 0;
const parser = new Parser();
let i = 0;
for (const link of links) {
song++;
const songLink = baseUrl + $list(link).attr('href');
const songLinkT = baseUrl + $listT(linksT[i]).attr('href');
const response = await downloader.download(songLink);
const responseT = await downloader.download(songLinkT);
const $ = cheerio.load(response);
const $T = cheerio.load(responseT);
const dirname = `${__dirname}/../../../../../../../ui/public/static/songs/`;
const parsedDownload = await parser.parse($);
await writeFile(
`${dirname}cmn-hans/${song}.json`,
JSON.stringify({ lines: parsedDownload.text }),
);
const parsedDownloadT = await parser.parse($T, undefined, $);
await writeFile(
`${dirname}cmn-hant/${song}.json`,
JSON.stringify({ lines: parsedDownloadT.text }),
);
i++;
}
}
开发者ID:pierophp,项目名称:pinyin,代码行数:53,代码来源:songs.ts
示例4: parseClassementLine
/**
* Transforme le bout de page passé en paramètre en objet classement
*
* @param ligne html a parser.
* @return objet classement
*/
public static parseClassementLine(line /**: DOM Element */): ClassementLine {
var $ = cheerio.load(line);
var lineChildren = $(line).children();
if (lineChildren !== null && lineChildren.length > 3) {
var nom = $(lineChildren[1]).text().trim().toUpperCase(),
points = $(lineChildren[2]).text(),
joue = $(lineChildren[3]).text(),
victoire = $(lineChildren[4]).text(),
nul = $(lineChildren[5]).text(),
defaite = $(lineChildren[6]).text(),
bp = $(lineChildren[8]).text(),
bc = $(lineChildren[9]).text(),
diff = $(lineChildren[11]).text();
var classementLine = new ClassementLine();
classementLine.nom = nom;
classementLine.points = points;
classementLine.joue = joue;
classementLine.gagne = victoire;
classementLine.nul = nul;
classementLine.perdu = defaite;
classementLine.bp = bp;
classementLine.bc = bc;
classementLine.diff = diff;
return classementLine;
} else {
return null;
}
}
开发者ID:orome656,项目名称:HOFCServer,代码行数:36,代码来源:parser_district_node_module.ts
示例5: function
Utils.downloadData(url, function(result) {
// do parse
var $5 = cheerio.load(result);
var title = $5('.post .title').text().trim();
var dateString = $5('.post .postmeta').text().trim();
var contents = $5('.post .entry').children();
var article="";
for(var i=0; i< contents.length;i++) {
if($5(contents[i]).attr('class') === 'sociable') {
break;
}
article += $5(contents[i]).text().trim();
article += "\n";
}
var jour = dateString.split(' ')[0];
if (jour.length === 1) {
jour = '0' + jour;
}
var mois = listeMoisActu[dateString.split(' ')[1]],
annee = dateString.split(' ')[2];
var resultats = new Article();
resultats.title = title;
resultats.date = annee + '-' + mois + '-' + jour + ' ' + '00:00:00';
resultats.article = article;
callback(resultats);
}, function(err) {
开发者ID:orome656,项目名称:HOFCServer,代码行数:31,代码来源:parser_node_module.ts
示例6: syncTest
syncTest('200 ok with title', (test) => {
let response = syncRequest('GET', settings.testSiteOrigin3);
test.equal(response.status, 200);
let $ = cheerio.load(response.body);
//console.log("bd: " + response.body);
test.equal($('body h1').text(), 'broken_test');
});
开发者ID:,项目名称:,代码行数:7,代码来源:
示例7: getUrlInfo
export async function getUrlInfo(url: string) {
if(!url.includes('http://') && !url.includes('https://')) {
url = `http://${url}`;
}
const html = await request(url);
const $ = cheerio.load(html);
let htmlInfo: any = {
'og:title':null,
'og:description':null,
'og:image':null
};
const meta = $('meta');
const keys = Object.keys(meta);
for (let s in htmlInfo) {
keys.forEach(function(key) {
if ( meta[key].attribs
&& meta[key].attribs.property
&& meta[key].attribs.property === s) {
htmlInfo[s] = meta[key].attribs.content;
}
})
}
htmlInfo.title = $('title').html();
return htmlInfo;
}
开发者ID:jgkim7,项目名称:blog,代码行数:27,代码来源:bookmarkService.ts
示例8: parseScrapedText
export const parseAccount = (html: string): Account => {
const $ = cheerio.load(html);
const result: { [key: string]: string } = {};
$('#content #tab-5 .column tbody tr').each((rowIndex, tableRow) => {
const cells: string[] = [];
$(tableRow)
.find('td')
.each((cellIndex, tableCell) => {
cells.push($(tableCell).html() || '');
});
result[camelCaseify(cells[0], ' ')] = parseScrapedText(cells[1]);
});
return {
firstName: result.firstName,
lastName: result.lastName,
address: result.address,
dateOfBirth: result.dateOfBirth,
phoneNumber: result.phoneNumber,
mobileNumber: result.mobileNumber,
emailAddress: result.emailAddress,
nameOnCard: result.nameOnCard,
cardType: result.cardType,
cardNumber: result.cardNumber,
cardExpires: result.cardExpires,
password: result.password,
opalPin: result.opalPin,
securityQuestion: result.securityQuestion,
securityAnswer: result.securityAnswer,
};
};
开发者ID:tbasse,项目名称:opaler,代码行数:34,代码来源:util.ts
示例9: parseInt
export const parseTransactions = (html: string): Transaction[] => {
const $ = cheerio.load(html);
const data: Transaction[] = [];
const noData = $('.no-activity-list').text();
if (noData !== '') {
return [];
}
$('#transaction-data tbody tr').each((rowIndex, tableRow) => {
const cells: string[] = [];
$(tableRow)
.find('td')
.each((cellIndex, tableCell) => {
cells.push($(tableCell).html() || '');
});
const [
transaction,
date,
mode,
details,
journey,
fareApplied,
fare,
discount,
amount,
] = cells;
const dataJson: Transaction = {
transactionNumber: parseInt(transaction, 10),
timestamp: parseTransactionDate(date),
summary: sanitizeSummaryString(details) || null,
mode: parseTransactionMode(mode) || null,
fare: {
applied: fareApplied || null,
price: Math.abs(dollarToInt(fare)) || 0,
discount: Math.abs(dollarToInt(discount)) || 0,
paid: Math.abs(dollarToInt(amount)) || 0,
},
journey: null,
};
if (dataJson.mode && /^(ferry|bus|train)$/.test(dataJson.mode)) {
const journeyData = dataJson.summary!.split(' to ');
if (journeyData.length === 2) {
dataJson.journey! = {
number: parseInt(journey, 10),
start: journeyData[0],
end: journeyData[1],
};
}
}
data.push(dataJson);
});
return data;
};
开发者ID:tbasse,项目名称:opaler,代码行数:60,代码来源:util.ts
注:本文中的cheerio.load函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论