当前位置: 首页 > 工具软件 > Fuzi > 使用案例 >

2_Fuzi_HTML的解析

吕修筠
2023-12-01
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 :(")
        }
    }
}
 类似资料: