httpHelper

package module
v0.0.0-...-a97b4a9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2018 License: Apache-2.0 Imports: 23 Imported by: 0

README

httpHelper

下载工具,方便配置代理,headers,简单的获取网页html内容,具体可以看demo.go

获取网站html内容
func GetHtmlDemo() {
  dst_url := "https://www.google.com"
  proxy_str := "socks5://127.0.0.1:1081"
  defaultCookieJar, _ := cookiejar.New(nil)
  var headerMap map[string]string = map[string]string{
    "User-Agent": GetRandomUserAgent(),
    "Referer":    "http://www.baidu.com",
  }
  //httpGet(dst_url string, proxy_str string, headerMap map[string]string, defaultCookieJar *http.CookieJar)

  _, response, _, err := HttpGet(dst_url, proxy_str, headerMap, defaultCookieJar)
  if err != nil {
    log.Fatal(err)
  }
  defer response.Body.Close()
  b, err := ioutil.ReadAll(response.Body)
  if err != nil {
    log.Fatal(err)
  }
  log.Println(string(b))

}
下载文件
func DownDemo() {
  proxy_str := "socks5://127.0.0.1:1081"
  var downBean DownEntity
  downBean.Down_url = "http://doshantianfang1.zgpingshu.com/%E5%8D%95%E7%94%B0%E8%8A%B3%E8%AF%84%E4%B9%A6_%E9%9A%8B%E5%94%90%E6%BC%94%E4%B9%89216%E5%9B%9E%E7%89%88216%E5%9B%9E1.13GB_32k/300043529F.mp3"
  downBean.Save_Root = "D:/down/go/zgps/"
  downBean.Save_name = "a.mp3"
  //	downBean.Save_path = downBean.Save_Root + downBean.Save_name
  downBean.Save_path = "a.mp3"
  downBean.Cor = 10
  downBean.Headers = map[string]string{
    "User-Agent":      "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0",
    "Referer":         "http://www.zgpingshu.com/down/1040/",
    "Accept-Encoding": "gzip",
  }
  MultithreadDownloader(downBean, proxy_str)
}

下载模块使用了@WindGreen 兄弟写的多线程下载模块,https://github.com/WindGreen/fileload 感谢额

Documentation

Overview

Utils

entityBean

fileload

Index

Constants

View Source
const VERSION = "1.0.3"

Variables

This section is empty.

Functions

func DeepCopy

func DeepCopy(dst, src interface{}) error

func Do

func Do(request *http.Request, fragment, no int)

func DownDemo

func DownDemo()

func GetClient

func GetClient(proxystr string, timeout int, defaultCookieJar *cookiejar.Jar, disableCompression bool) *http.Client

获取配置http.Client 代理配置,超时,默认cookie,是否启用压缩

func GetCurrentPath

func GetCurrentPath() (string, error)

获取执行文件当前路径

func GetHtmlDemo

func GetHtmlDemo()

func GetRandomUserAgent

func GetRandomUserAgent() string

获取随机User-Agent

func HttpGet

func HttpGet(dst_url string, proxy_str string, headerMap map[string]string, defaultCookieJar *cookiejar.Jar) (*http.Request, *http.Response, *http.Client, error)

func HttpHeaderBuild

func HttpHeaderBuild(request *http.Request, headerMap map[string]string)

构建http header

func MultithreadDownloader

func MultithreadDownloader(downbean DownEntity, proxy_str string)

cnum 线程数,savePath 保存路径 durl 下载路径 func MultithreadDownloader(cor int, pdst string, durl string) {

Types

type DownEntity

type DownEntity struct {
	Down_url  string
	Save_path string
	Save_Root string
	Headers   map[string]string
	Cor       int
	Save_name string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL