code

package main

import (
	//"io/ioutil"
	//	"bytes"
	"fmt"
	//"io/ioutil"
	"os"
	"syscall"
	"unsafe"
	//"strings"

	//"github.com/PuerkitoBio/goquery"
	//"github.com/andybalholm/cascadia"
	//"golang.org/x/net/html"
)

/*
var allNodes = `<!doctype html>
<html>
	<head>
		<meta a="b">
	</head>
	<body>
		<p><!-- this is a comment -->
		This is some text.
		</p>
		<div></div>
		<h1 class="header">wangyanqiu</h1>
		<h2 class="header">wanglu</h2>
		<h2 class="header">wanghuan</h2>
		<h2 id="jj">wanghuan</h2>
	</body>
</html>`

func TestNodeName() {

	bs, _ := ioutil.ReadFile("基于 Golang 的垂直个性爬虫框架 go_spider - 推酷.html")
	doc, err := goquery.NewDocumentFromReader(bytes.NewReader(bs))
	if err != nil {
		//t.Fatal(err)
		fmt.Println("wyq", err)
	}
	if doc.Url != nil {
		fmt.Println(doc.Url.Path)
	} else {
		fmt.Println("doc.Url is null")
	}
	content, bExist := doc.Find("a").Attr("href")
	if bExist {
		fmt.Println(content)
	} else {
		fmt.Println(bExist)
	}

	//ses := doc.Find("a").Find("[href]").First()
	//ses := doc.Find("a").Find("[href]")
	ses := doc.Find("[href]").Last()
	if ses != nil {
		content, _ := ses.Attr("href")
		fmt.Println("link:", content)
		a, _ := ses.Html()
		fmt.Println(ses.Text(), ses.Length(), a)
		fmt.Println("wyq")
	} else {
		fmt.Println("ses is null")
	}


}
*/
/*
func GetJokes() {
	doc, err := goquery.NewDocument("http://www.qiushibaike.com")
	if err != nil {
		//log.Fatal(err)
		fmt.Println(err)
	}
	doc.Find(".content").Each(func(i int, s *goquery.Selection) {
		fmt.Println(i, s.Text())
	})
}
*/
func vf(a ...int) int {
	if len(a) == 0 {
		return 0
	}
	var x int
	for _, v := range a {
		x, _ = fmt.Println(v)
	}
	return x
}

type A struct {
	a int16
	b int16
	c float64
}

type B struct {
	a int16
	b int16
	c float64
}

func main() {

	var aObj A
	ptr := unsafe.Sizeof(aObj)
	ptr1 := unsafe.Alignof(aObj)
	ptr2 := unsafe.Offsetof(aObj.c)
	ptr3 := (*B)(unsafe.Pointer(&aObj))
	ptr4 := *(*B)(unsafe.Pointer(&aObj))

	fmt.Println(ptr, ptr1, ptr2, ptr3, ptr4)

	//var a A
	//fmt.Println(unsafe.Pointer(uintptr(a) + unsafe.Offsetof(a.c)))

	f, _ := os.Open("/home/wyq/mygo/test1/main.go")
	defer f.Close()
	n := 4086
	p := make([]byte, 4086)
	fmt.Println("test")
	//syscall.Syscall(syscall.SYS_READ, uintptr(int(f.Fd())), uintptr(unsafe.Pointer(&p[0])), uintptr(n))
	syscall.Syscall(syscall.SYS_READ, f.Fd(), uintptr(unsafe.Pointer(&p[0])), uintptr(n))
	fmt.Println(p)
	/*
		_, err := syscall.Read(int(f.Fd()), p)
		if err != nil {
			fmt.Println("err", err)
		}
		fmt.Println("data:", p)
		p1 := make([]byte, 4086)
		p1, err = ioutil.ReadFile("/home/wyq/mygo/test1/main.go")
		fmt.Println("d:", p1)
		println("d:", p1)
	*/
}

转载于:https://my.oschina.net/julian115/blog/758287

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值