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