Categorygithub.com/ghostljj/gspider
modulepackage
1.1.7
Repository: https://github.com/ghostljj/gspider.git
Documentation: pkg.go.dev

# README

欢迎使用gspider 蜘蛛 爬虫 采集

快速采集网页

开始

安装

$ go get -u github.com/ghostljj/gspider
python 有大名鼎鼎的requests
golang 有gspider 大致使用差不多
支持http代理,Socks5代理

例子

package main

import (
        "fmt"
        gs "github.com/ghostljj/gspider"
)

func main() {
	var strUrl string
	strUrl = "http://2022.ip138.com/ic.asp"
	//strUrl = "http://www.baidu.com"
	//strUrl = "http://www.google.com"

	req := gs.Session()
	//ss.SetHttpProxy(fmt.Sprintf("http://%s:%d", "127.0.0.1", 10809))
	//ss.SetSocks5Proxy("127.0.0.1:10808", "", "")

	res := req.Get(strUrl,
		gs.OptRefererUrl("http://www.baidu.com"),
		gs.OptCookie("aa=11;bb=22"),
		gs.OptHeader(map[string]string{"h1": "v1", "h2": "v2"}),
	)
	res.Encode = "utf-8"
	if res.GetErr() != nil {
		fmt.Println("Error=" + res.GetErr().Error())
	} else {
		fmt.Println()
		fmt.Println()
		fmt.Println()
		fmt.Println()
		fmt.Println(res.GetContent())
		res.PrintReqHeader("") //打印 请求 头信息
		res.GetReqHeader()
		res.PrintReqPostData()            // 打印 请求 PostData
		res.PrintResHeader("")            //打印 响应 头信息
		res.PrintResSetCookie()           //打印 响应 头信息SetCookie
		res.PrintResUrl()                 // 打印 响应 最后的Url
		res.PrintCookies(res.GetResUrl()) // 获取 响应 最后的Url 的 Cookie
		res.PrintStatusCode()             // 打印 响应 状态码
	}
}

为什么打印些无用的东西给我?
因为,这就是调试信息,仔细看会发现使用函数哈。
打印后慢慢磨控制台,会有惊喜


可以Post, Get, PostJson,GetJson 等  有示例2 有空可以看看

Post 时注意,送给同学们url.QueryEscape 这个函数,用于参数编码,会有用的。Post json请忽略

还有就是可以获取图像Base64字符串,使用GetBase64Image

设置Cookies

    SetCookies(strUrl, "NewKey1=NewValue1;NewKey2=NewValue==99=2;")

清空Cookies

     ResetCookie()

获取Cookies

    Cookies(strUrl)

题外话:获取 Cookie Json 可用于Chrome的 EditThisCookie 插件 当你知道某网站的Cookie时,使用这个可以生成能用EditThisCookie导入Cookie里面。例如一些已登录的网站。

    gspider.GetCookieJson(strUrl, strCookie)

# Functions

GetCookieJson 一个全局方法 可以获取cookie json 可用于chrome的 EditThisCookie 插件 strUrl: 为设置cookie的url strCookie: 为浏览器cookie字段列,例如 aaa=111;bbb=222;ccc=333 返回Json 字符串,可以使用 EditThisCookie 导入到浏览器。只要记录这段数据,日后未登录的用户马上变成登录,不过需要注意超时问题.
GetCookiesMap 获取Cook的map[string]string.
LoadCa 加载ca字节.
LoadCaFile 加载ca文件.
OptCookie 设置当前Url cookie.
OptCookieAll 设置当前Url+根Url cookie.
OptHeader 设置发送头.
OptKeepAliveTimeout 设置保持连接,超时.
OptReadWriteTimeout 设置读写超时.
OptRedirectCount 重定向次数.
OptRefererUrl 设置来源地址,返回接口指针(新建一个函数,不执行的,返回他的地址而已).
OptTimeout 设置超时.
Session 创建Request对象.

# Variables

No description provided by the author

# Structs

Request 这是一个请求对象 .
No description provided by the author
HttpInfo 返回信息结构.

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author