• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript cheerio.default函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中cheerio.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了default函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: products

  get products() {
    const products = []
    const prods = this.productItems

    for (let i = 0; i < prods.length; i++) {
      const p = prods[i]
      const product = new Product()

      const prodImgElm = cheerio('.item_thumb img', p)[0]
      product.productImage = prodImgElm.attribs.src.replace('/large-', '/original-')
      product.coverImageUrl = product.productImage

      product.coverImageFile = {
        name: 'coverImage' + path.extname(product.productImage),
        downloadUrl: product.productImage,
      }

      const prodLinkElm = cheerio('a.item_thumb', p)
      product.productUrl = 'https://www.teacherspayteachers.com' + prodLinkElm[0].attribs.href

      const itemTitleElm = cheerio('a.title', p)[0]
      product.title = itemTitleElm.children[0].data.trim()

      const itemDescElm = cheerio('div.description', p)[0]
      product.description = itemDescElm.children[0].data.trim()

      const itemAuthorElm = cheerio('div.author', p)
      product.authorId = itemAuthorElm.find('a').attr('data-id')

      let categoryItemsHTML = cheerio('.category_item', p)

      let priceTagElm = cheerio('div.price', p)[0]
      const priceInfo = concatText(priceTagElm).trim()

      product.licence = priceInfo === 'FREE' ? 'FREE' : 'PAID'
      product.price = priceInfo === 'FREE' ? undefined : priceInfo

      for (let j = 0; j < categoryItemsHTML.length; j += 1) {
        const ci = categoryItemsHTML[j]

        const categoryItemNameElm = cheerio('.category_name', ci)[0]
        let categoryItemName = categoryItemNameElm.children[0].data.trim()
        categoryItemName = categoryItemName.substring(0, categoryItemName.length - 1)

        let civ = cheerio('.category_values', ci)[0]
        const civs = cheerio('a', civ)
        const categoryItemValues = []

        for (let k = 0; k < civs.length; k++) {
          const categoryItemValue = concatText( civs[k] )
          categoryItemValues.push(categoryItemValue)
        }
        switch (categoryItemName) {
          case 'Types':
            product.resourceTypes = categoryItemValues.map(val => {return {title: val, id: val}})
            break
          case 'Grades':
            product.years = categoryItemValues.map(val => {return {title: val, id: val}})
            break
          case 'Subjects':
            product.subjects = categoryItemValues.map(val => {return {title: val, id: val}})
            break
          default:
        }
      }

      const itemActions = cheerio('a', p)
      const links: any = {}
      for (let j = 0; j < itemActions.length; j++) {
        const href = itemActions[j].attribs.href;
        if (href.match("/Product/")) {
          const m = href.split("/")
          const productUri = m[m.length - 1]
          const productUriParts = productUri.split("-")
          product.productId = productUriParts[productUriParts.length - 1]
          links.downloadUrl =  'https://www.teacherspayteachers.com/Download/' + productUri
          links.productUrl = href
          break;
        }
      }

      product.files = [
        {
          name: 'primary-download',
          realName: 'primary-download',
          downloadUrl: links.downloadUrl,
          resourceType: product.resourceTypes,
        },
      ]

      product.siteRef = 'TPT'
      product.country = 'GB'
      product.resourceOrigin = TPTUrls.BASE_URL

      products.push(product)
    }
    return products

  }
开发者ID:tes,项目名称:resource-backup-tool,代码行数:99,代码来源:TPTShopPage.ts


示例2: products

  get products() {
    const products = []
    const prods = this.productItems

    for (let i = 0; i < prods.length; i++) {

      const product = new Product()
      const p = prods[i]

      product.siteRef = 'TNB'
      product.resourceOrigin = TNBUrls.BASE_URL
      product.country = 'GB'

      const smallThumbElm: any = Array.from(cheerio('.thumbimg', p))[0]
      product.productId = smallThumbElm.attribs.nid

      const prodImgElm = cheerio('.prod_image_holder img', p)[0]
      product.productImage = prodImgElm.attribs.src
      product.coverImageUrl = product.productImage

      product.coverImageFile = {
        name: 'coverImage' + path.extname(product.productImage),
        downloadUrl: product.productImage,
      }

      let priceTagElm = cheerio('div.prod_final_price_default', p)[0]
      const priceInfo = concatText(priceTagElm).trim()
      product.licence = priceInfo === 'FREE' ? 'FREE' : 'PAID'
      product.price = priceInfo === 'FREE' ? undefined : priceInfo

      const wishListOnClick = cheerio('.prod_details_wishlist_text', p)[0].attribs.onclick
      const uidStart = wishListOnClick.indexOf('(') + 1
      const uidEnd = wishListOnClick.indexOf(',')
      product.authorId = wishListOnClick.substring(uidStart, uidEnd)

      const prodLinkElm = cheerio('a', p)
      product.links = {
        productUrl: 'https://www.teachersnotebook.com/' + prodLinkElm[0].attribs.href.substring(1),
        downloadUrl: priceInfo === 'FREE'
          ? 'https://www.teachersnotebook.com/freefiles/' + product.productId
          : 'https://www.teachersnotebook.com/downloadfile/0/' + product.authorId + '/' + product.productId,
      }

      const itemTitleElm = cheerio('.prod_details_title_name', p)[0]
      product.title = itemTitleElm.children[0].data.trim()

      const itemDescElm = cheerio('.prod_details_title_desc', p)[0]
      product.description = itemDescElm.children[0].data.trim()

      const resourceTypesElm = cheerio('div.prod_details_resource_holder .prod_details_right', p)
      product.resourceTypes = concatText(resourceTypesElm[0]).split(', ').map(e => {return {id: e, title: e}})

      const subjectsElm = cheerio('div.prod_details_categories_holder .prod_details_right', p)
      product.subjects = concatText(subjectsElm[0]).split(', ').map(e => {return {id: e, title: e}})

      const gradesElm = cheerio('div.prod_details_grades_holder .prod_details_right .prod_grade_level', p)
      const gradesGroupElm = cheerio('div.prod_details_grades_holder .prod_details_right .prod_grade_level_group', p)

      product.years = Array.from(gradesElm).concat(Array.from(gradesGroupElm))
        .map( gradeElm => concatText(gradeElm) ).map(e => {return {id: e, title: e}})

      product.files = [
        {
          name: 'primary-download',
          downloadUrl: product.links.downloadUrl,
          resourceType: product.resourceTypes,
        },
      ]

      products.push(product)
    }
    return products
  }
开发者ID:tes,项目名称:resource-backup-tool,代码行数:73,代码来源:TNBShopPage.ts


示例3: callback

// TODO: Function overloading?
	__render(html, callback: RenderCallback) {
		var $scope = null;
		var $cheerio = $;

		if (_.isString(html)) {
			$scope = $.load(html)(this._documentSelector);
		} else if (_.isObject(html)) {
			$scope = $(html).find(this._documentSelector); // must be DOM
		} else {
			return callback(new Error('Must be Cheerio DOM object'), null, null);
		}

		if (this._documentSelectorIndex) {
			try {
				$scope = $($scope[this._documentSelectorIndex]);
			} catch (e) {
				throw new Error('No selector index at "' + this._documentSelectorIndex + '"');
			}
		}

		// monkey patch $scope
		$scope.$find = MenioModel.__find($scope);

		let self = {
			model: {}
		};
		_.extend(self, this._props);


		for (let i = 0; i < this._keys.length; i++) {
			let name = this._keys[i];

			try {
				// DI - scope, cheerio and _
				let opts = this._mappings[i].call(self, $($scope), $cheerio, _);

				// only call next if callback and next
				if (callback && opts && opts.next) {
					callback(null, opts.$scope, self.model);
					return;
				} else {
					if (!self.model[name]) {
						self.model[name] = opts;
					}
				}
			} catch (e) {
				throw e;
			}

		}

		if (callback) {
			return callback(null, null, self.model);
		} else {
			return self.model;
		}

	};
开发者ID:molekilla,项目名称:menio,代码行数:59,代码来源:menio.ts


示例4: function

		return function(selector:string, index:number) {
			let scope;

			if (!selector) {
				throw new Error('Missing selector');
			}

			if (index) {
				scope = $(rootScope.find(selector)[index]);
			} else {
				scope = $(rootScope.find(selector));
			}

			scope.$find = MenioModel.__find(scope);
			return scope;
		};
开发者ID:molekilla,项目名称:menio,代码行数:16,代码来源:menio.ts


示例5:

/*
 * LOADING
 */
let html =
`<ul id="fruits">
  <li class="orange">Apple</li>
  <li class="class">Orange</li>
  <li class="pear">Pear</li>
  <input type="text" />
</ul>`;

// Preferred Method
var $ = cheerio.load(html);
// Directly load element
cheerio(html);
cheerio('ul', html);
cheerio('li', 'ul', html);

$ = cheerio.load(html, {
    normalizeWhitespace: true,
    xmlMode: true
});

$ = cheerio.load(html, {
    normalizeWhitespace: true,
    xmlMode: true,
    decodeEntities: true,
    lowercaseTags: true,
    lowerCaseAttributeNames: true,
    recognizeCDATA: true,
开发者ID:iondrive,项目名称:DefinitelyTyped,代码行数:30,代码来源:cheerio-tests.ts



注:本文中的cheerio.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript cheerio.load函数代码示例发布时间:2022-05-24
下一篇:
TypeScript chat.ChatCtrl类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap