Skip to content

shinima/temme

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Build Status Coverage Status NPM Package Node Version Requirement VSCode Extension Example Fangwen Example Douban Movie

English Version

temme

temme 是一个类 jQuery 的选择器,用于简�?优雅地从 HTML 文档中�??�?�所需的 JSON 数�?�。

例�?

<!-- 下�?�用到的 html 的内容 -->
<ul>
  <li data-fruit-id="1">
    <span data-color="red">apple</span>
  </li>
  <li data-fruit-id="2">
    <span data-color="white">pear</span>
  </li>
  <li data-fruit-id="3">
    <span data-color="purple">grape</span>
  </li>
</ul>

对于上�?�的 html,我们�?�以使用下�?�的 temme 选择器�?��??�?�「水果颜色和�??称的列表�?。(在线版本链接)

import temme from 'temme'
// 使用 commonjs 导入时需�?加上 .default
// const temme = require('temme').default

const selector = `li@fruits {
  span[data-color=$color]{$name};
}`
temme(html, selector)
//=>
// {
//   "fruits": [
//     { "color": "red", "name": "apple" },
//     { "color": "white", "name": "pear"  },
//     { "color": "purple", "name": "grape" }
//   ]
// }

如果你对 temme 还�?熟悉,那么�?�以从 豆瓣电影的例�? 开始。在线版本中也包�?�了一些其他较短的例�?。比如这个例�?从豆瓣电影页�?�中抓�?�了电影的基本信�?�和评分信�?�。这个例�?从天猫的商�?详情页�?�中抓�?�了评论列表,包括用户的基本信�?�,�?次评价和追加评价, 以�?�晒的照片的链接.