2_Fuzi_HTML的解析

该文章展示了一个iOS应用的Podfile,其中引入了Fuzi库来解析HTML文档。代码示例中,提取了HTML文件的版权信息,链接(包括内联样式和外部脚本链接),以及通过XPath查询获取页面元素,如锚点和脚本标签。此外,还展示了如何计算页面上锚点的数量并获取文档的标题、头部和主体内容。
摘要由CSDN通过智能技术生成
platform :ios, '13.0'
use_frameworks!

target 'DemoApp' do
    source 'https://github.com/CocoaPods/Specs.git'
    pod 'Fuzi'
end
  • index.html
<!--
Author: Jerry
Author URL: http://www.hdjc8.com
License: Creative Commons Attribution 3.0 Unported
License URL: http://www.hdjc8.com
-->
<!DOCTYPE html>
<html>
<head>
<title>Interactive Tutorials</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
<link href='//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800' rel='stylesheet' type='text/css'>
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/easyResponsiveTabs.js" type="text/javascript"></script>

</head>
<body>
	<!-- main -->
    <a href="index.html">Home</a>
	<div class="main" id="container">
		<h1>Trendy Tab Login Form</h1>
		<div class="login-form">
			<div class="sap_tabs w3ls-tabs">
				<div id="horizontalTab" style="display: block; width: 100%; margin: 0px;">
					<ul class="resp-tabs-list">
						<li class="resp-tab-item" aria-controls="tab_item-0" role="tab"><span>Login</span></li> 
						<li class="resp-tab-item" aria-controls="tab_item-1" role="tab"><label>/</label><span>Sign up</span></li>
					</ul>	
					<div class="clear"> </div>
					<div class="resp-tabs-container">
						<div class="tab-1 resp-tab-content" aria-labelledby="tab_item-0">
							<div class="login-agileits-top"> 
								<form action="#" method="post">
									<p>User Name </p>
									<input type="text" name="User Name" required=""/>
									<p>Password</p>
									<input type="password" name="Password" required=""/>	 
									<input type="checkbox" id="brand" value="">
									<label for="brand"><span></span> Remember me ?</label> 
									<input type="submit" value="LOGIN">
								</form>  
							</div>
							<div class="login-agileits-bottom"> 
								<p><a href="forgotPassword.html">Forgot password?</a></p>
							</div> 
						</div> 
						<div class="tab-1 resp-tab-content" aria-labelledby="tab_item-1">
							<div class="login-agileits-top sign-up"> 
								<form action="#" method="post">
									<p>User Name </p>
									<input type="text" name="User Name"  required=""/>
									<p>Your Email </p>
									<input type="text" name=Email"  required=""/>
									<p>Password</p>
									<input type="password" name="Password" placeholder="" required=""/>	
									<input type="checkbox" id="brand1" value="">
									<label for="brand1"><span></span>I accept the terms Use</label> 
									<input type="submit" value="SIGN UP">
								</form>  
							</div>
						</div>
					</div>							
				</div>	 
			</div> 
			<!-- ResponsiveTabs js -->
			<script type="text/javascript">
				$(document).ready(function () {
					$('#horizontalTab').easyResponsiveTabs({
						type: 'default', //Types: default, vertical, accordion           
						width: 'auto', //auto or any width like 600px
						fit: true   // 100% fit in a container
					});
				});
			</script>
			<!-- //ResponsiveTabs js -->
		</div>	
	</div>	
	<!-- //main -->
	<!-- copyright -->
	<div class="copyright" id="copyright">
		<p> © 2020 Trendy Tab Login Form . All rights reserved | Design by <a href="http://w3layouts.com/" target="_blank">W3layouts</a></p>
	</div>
	<!-- //copyright --> 
</body>
</html>
import UIKit
import Fuzi
class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        yeTyeHtml()
    }
    
    func yeTyeHtml(){
        let fileUrl = URL(fileURLWithPath: ((#file as NSString).deletingLastPathComponent as NSString).appendingPathComponent("index.html"))
        do
        {
            let data = try Data(contentsOf: fileUrl)
            let doc = try HTMLDocument(data: data)
            
            if let elementById = doc.firstChild(css: "#copyright")
            {
                print("---\(elementById.stringValue)--")
                // © 2020 Trendy Tab Login Form . All rights reserved | Design by W3layouts
            }
            
            print("---1--")
            for link in doc.css("a, link")
            {
                print(link.rawXML)
                print(link["href"] as Any)
            }
            
            print("---2--")
            if let firstAnchor = doc.firstChild(xpath: "//body/a")
            {
                print(firstAnchor["href"] as Any)
                //Optional("index.html")
            }
            
            print("---3--")
            for script in doc.xpath("//head/script")
            {
                print(script["src"] ?? "")
                //js/jquery.min.js
                //js/easyResponsiveTabs.js
            }
            
            print("---4--")
            if let result = doc.eval(xpath: "count(//body/a)")
            {
                print("anchor count : \(result.doubleValue)") //anchor count : 1.0
            }
            
            print("---5--")
            print(doc.title as Any)
            print(doc.head as Any)
            print(doc.body as Any)
        }
        catch
        {
            print("Something went wrong :(")
        }
    }
}
### 回答1: be2works_v4.52_bohol_fu11-pw_radiokot.rar是一个软件程序,是一个用于编程和配置车用ECU(发动机控制单元)的工具。其名称中的“be2works”表示该程序是由Be2Works开发的,而“v4.52”表示该程序的版本号为4.52。“bohol_fu11-pw_radiokot.rar”可能是该程序的压缩包名称,包括某些自定义设置或一些特定的ECU编程文件。 该程序的主要用途是为车辆的电子控制单元编写和编辑程序代码,这些代码负责控制发动机的性能和行驶状态。使用该程序可以改变ECU设置,例如调整引擎转速限制,限制油门响应等。而使用压缩包,则可以方便地共享与使用ECU编程文件。 该程序需要一定的专业知识和技能才能操作,因此建议使用者在使用之前必须慎重考虑,同时请确保遵守相关的法规和安全要求,避免对车辆和自己产生不必要的损害。 ### 回答2: be2works_v4.52_bohol_fu11-pw_radiokot.rar 是一个文件压缩包,其中包含一个名为 be2works_v4.52 的软件。这个软件主要用于编程和调整电池管理系统中的参数,特别是用于电动车和太阳能电池等领域。用户可以通过该软件对电池进行充电、放电和平衡,以确保其工作正常和稳定。此外,该软件还提供了报告生成和数据记录功能,使用户能够轻松追踪自己的电池的性能和状态。be2works_v4.52_bohol_fu11-pw_radiokot.rar 包含了该软件的完整安装程序和必要的库文件,用户可以快速进行安装和启动使用。总之,be2works_v4.52_bohol_fu11-pw_radiokot.rar 是一个方便实用的电池管理软件,可提供用户高效的电池管理解决方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值