-

xiyueta.js库 - 入门指南

xiyueta.js库是一个快速解析html字符串遍历网页dom结构的JavaScript库。它通过与jQuery语法使用一致的 API 使 html文档遍历和处理更加简单。xiyueta.js库是先解析网页html文本再遍历html网页dom,xiyueta.js库可以在WEB浏览器里使用,也可以在ASP程序里使用,也可以在nodejs里使用。 xiyueta库在nodejs里使用和cheerio使用方法差不多,xiyueta库比cheerio库增加了一些自定义属性方法和工具方法。 xiyueta.js库设计的宗旨是“write Less,Do More”,即倡导写更少的代码,做更多的事情。xiyueta的核心特性可以总结为:具有独特的链式语法和短小清晰的多功能接口。

xiyueta

xiyueta.js库兼容性和面向场景

xiyueta.js库兼容绝大多数浏览器,可作为 HTML/CSS文档解析遍历dom助手。
xiyueta.js库同时也可以在nodejs环境里使用,也可以在ASP程序里使用。

获得 xiyueta

1. 官网首页下载

你可以在我们的 官网首页 下载到 xiyueta的最新版,它经过了自动化构建,更适合用于生产环境。
或到csdn下载最新版 xiyueta.js库
或到chinaz站长下载最新版 xiyueta.js库
目录结构如下:

  ├─xiyueta.min.js //核心库
  │  
  └─src  //源码目录
    ├─xiyueta.js       //HTML解析库 + 属性方法及工具方法 (4000多行代码)
    ├─xiyueta.css.js   //CSS解析库 + 属性方法及工具方法
    ├─xiyueta.asp.js   //ASP解析库 + 属性方法及工具方法
    ├─xiyueta.more.js  //xiyueta.js库更多自定义属性方法+工具方法
    ├─common.js        //公共函数库
    ├─url.js           //网址处理
    ├─handle.js        //HTML网页处理
    ├─xiyueta.debug.js //调试函数库
    └─tpl.js           //模板库
     

2. Git 仓库下载

你也可以通过 GitHub码云CodeChina 得到 xiyueta的完整开发包,以便于你进行二次开发

在安装git后,在新建目录里运行cmd,然后运行下载命令,下载xiyueta.js库到本地
git clone https://github.com/313801120/xiyueta.git
git clone https://gitee.com/313801120/xiyueta.git
git clone git@gitcode.net:qq313801120/xiyueta.git

3. npm 下载

你也可以通过 npm 得到 xiyueta的完整开发包,以便于你进行二次开发
 

npm i xiyueta                下载最新版xiyueta.js库
npm view xiyueta versions    查看xiyueta库全部版本
npm install xiyueta@1.0.0    安装xiyueta指定版本
npm ls xiyueta               查看本地xiyueta包版本号
npm update xiyueta           更新xiyueta.js库
      

快速上手xiyueta.js库

如果你将 xiyueta 下载到了本地,那么可将其完整地放置到你的项目目录(或静态资源服务器)
尝试一下>>

  • web代码
  • nodejs代码
  • asp代码
  • php代码
  • vb6代码
  • vs10代码
  • python代码
  • 效果
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>Start using xiyueta JS Library</title>
</head>
<body>
 
<!-- Your HTML code -->
 
<script src="https://www.xiyueta.com/js/xiyueta.min.js"></script>
<script>
  $.load("<div>hello world!</div>"); //Parsing HTML
  $("div").text("xiyueta.com"); //Set page div
  alert($.html())
</script> 
</body>
</html>
var $ = require('xiyueta')

$.load("<div>hello world!</div>"); //Parsing HTML
$("div").text("xiyueta.com"); //Set page div
console.log( $.html() )
<script  language="javascript" runat="server" src="./dist/asp.xiyueta.min.js"></script> 
<%
xiyueta.load("<div>hello world!</div>") 'Parsing HTML
xiyueta("div").text("xiyueta.com") 'Set page div
console.log( xiyueta.html() )
%>
php代码详细介绍
<?php 
// 指定要写入的文件路径
$file_path = "debug/test001/example.js";
// 要写入文件的数据
$data= "const xiyueta = require('xiyueta') \n";
$data.="xiyueta.load('

qq:313801120

') \n"; $data.=" console.log( xiyueta('p').text() ) \n"; // 以写入模式打开文件 $file = fopen($file_path, "w") or die("无法打开文件!"); // 将数据写入文件 fwrite($file, $data); // 关闭文件 fclose($file); $output=shell_exec("node ".$file_path); echo($output);
vb代码下载案例

Private Sub Form_Load()
    Dim sc, html, s
    Set sc = CreateObject("ScriptControl")
    sc.language = "Jscript" '设置语言为javascript
    sc.Timeout = -1
    sc.AddCode getFText("asp.xiyueta.min.js")
    sc.AddCode getFText("1.js")
     
    
    s = sc.Eval(" $.load('<div>hello world!</div>');$('div').text('xiyueta.com');$.html()")
    MsgBox (s)   '<div>xiyueta.com</div>
    
    
    
    '两种调用方法
    'Sc.Run("mytestfun", html)
    'Sc.Eval(" xiyueta.load('" & html & "');xiyueta('div').text()")
End Sub

'读文件内容
Function getFText(filePath)
    Dim fso, fText, openFile
    filePath = App.Path & "/" & filePath
    Set fso = CreateObject("Scripting.FileSystemObject")
        If fso.fileExists(filePath) = True Then
            Set fText = fso.OpenTextFile(filePath, 1)
                '加强 读空文件出错
                Set openFile = fso.getFile(filePath)
                    If openFile.Size = 0 Then getFileText = "": Exit Function                       '文件为空则退出
                Set openFile = Nothing
                getFText = fText.ReadAll
                 
            Set fText = Nothing
        End If
    Set fso = Nothing
End Function
vs10代码下载案例
Imports MSScriptControl
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sc
        sc = CreateObject("ScriptControl")
        sc.language = "Jscript" '设置语言为javascript
        sc.Timeout = -1
        sc.AddCode(getFText("asp.xiyueta.min.js"))
        sc.AddCode(getFText("1.js"))

        Dim txtHtml = "<div>aaa</div><div>bbb</div><div>ccc</div>"


        '两种调用方法
        'Sc.Run("mytestfun", html)
        Dim s = sc.Eval(" xiyueta.load('" & txtHtml & "');;xiyueta('div').text()")
        MsgBox(s)
        s = sc.Eval("xiyueta('div:eq(0)').text()")
        MsgBox(s)

        Call sc.Run("load", txtHtml)

    End Sub


    '读文件内容 (2013,9,27
    Function getFText(ByVal filePath As String)
        Dim fso, fText, openFile
        getFText = ""   '它默认返回的就是空, 这个是多此一举 (2013,9,30)
        filePath = Application.StartupPath() & "/" & filePath
        '获得完整路径
        fso = CreateObject("Scripting.FileSystemObject")
        If fso.fileExists(filePath) = True Then
            fText = fso.openTextFile(filePath, 1)
            '加强 读空文件出错
            openFile = fso.getFile(filePath)
            If openFile.Size = 0 Then getFText = "" : Exit Function '文件为空则退出
            openFile = Nothing
            getFText = fText.readAll
            fText = Nothing
        End If
        fso = Nothing
    End Function


End Class
2.py文件代码 下载案例
# 导入执行JS代码模块 <需要安装>
import execjs              #安装 pip install PyExecJS

f=open('6.js', encoding='utf-8').read()
js_code = execjs.compile(f) 

txt = js_code.call('test','
hello world!
','div') print(txt)
6.js文件代码
const xiyueta = require('xiyueta')    //安装  npm install xiyueta

function test(html,selector){
    xiyueta.load(html)    
    xiyueta('div').text('xiyueta.com');
    return xiyueta.html();
} 
<div>xiyueta.com</div>

xiyueta自定义方法

xiyueta中添加自定义属性方法1,如:
$.fn.extend({'aa':function(){}})

xiyueta.fn.aa=function(){}
调用方法 $().aa()

xiyueta中添加自定义工具方法2,如:
xiyueta.aa=function(){}

$.extend({'aa':function(){}})
调用方法 $.aa()
<script src="https://www.xiyueta.com/js/xiyueta.min.js"></script>
<script type="text/javascript">  
 
//自定义属性方法第一种
xiyueta.fn.myFuncOne=function(){
    alert("我的自定义xiyueta方法1");
}
$().myFuncOne();//调用方法
 
//自定义属性方法第二种
xiyueta.fn.extend({
    'myFuncTow':function(){
        alert("我的自定义xiyueta方法2");
    }
})
$().myFuncTow();//调用方法
 
//自定义工具方法第三种
xiyueta.myFuncThree=function(){
    alert("我的自定义xiyueta方法3");
}
$.myFuncThree();//调用方法
 
//自定义工具方法第四种
xiyueta.extend({
    'myFuncFour':function(){
        alert("我的自定义xiyueta方法4");
    }
})
$.myFuncFour();//调用方法
 
</script>
          

xiyueta - 在每一个细节中,用心做到最好。 作者QQ 313801120