package main

import (
"fmt"
"github.com/gocolly/colly"
"github.com/gocolly/colly/proxy"
"strconv"
"strings"
"log"
pTool "./mypack"
) type ProxyIp struct {
Ip string
Port int
IsHttps bool
UpdateTime int
SourceUrl string
TimeTolive int
AnonymousInfo string
Area string
InternetServiceProvider string
} var ProxyIpPool []ProxyIp func main() {
p := &ProxyIpPool
SourceUrl := "http://www.xicidaili.com/nt/"
// Instantiate default collector
c := colly.NewCollector(
// MaxDepth is 2, so only the links on the scraped page
// and links on those pages are visited
colly.MaxDepth(1),
colly.Async(true),
) // Limit the maximum parallelism to 1
// This is necessary if the goroutines are dynamically
// created to control the limit of simultaneous requests.
//
// Parallelism can be controlled also by spawning fixed
// number of go routines.
c.Limit(&colly.LimitRule{DomainGlob: "*", Parallelism: 12}) // On every a element which has href attribute call callback
c.OnHTML("tr", func(e *colly.HTMLElement) {
var item ProxyIp
e.ForEach("td", func(i int, element *colly.HTMLElement) {
t := element.Text
switch i {
case 1:
item.Ip = t
break
case 2:
p, n := strconv.Atoi(t)
if n == nil {
item.Port = p
}
break
case 3:
item.Area = t
break
case 4:
item.IsHttps = strings.Contains(strings.ToLower(t), "https")
break
default:
break
} })
item.SourceUrl = SourceUrl
*p = append(*p, item)
}) // Start scraping on https://en.wikipedia.org
c.Visit(SourceUrl)
// Wait until threads are finished
c.Wait() fmt.Println(*p)
fmt.Println("fmt.Println(*p)----------------------------------->") var a [] string
for _, v := range *p {
http := "http"
if v.IsHttps {
http = "https"
}
if v.Ip != "" && v.Port != 0 {
s := http + "://" + v.Ip + ":" + strconv.Itoa(v.Port)
fmt.Println(s)
a = append(a, s)
}
} fmt.Println("fmt.Println(*p)<-----------------------------------")
c = colly.NewCollector(
colly.AllowedDomains("cn.sonhoo.com"),
) rp, err := proxy.RoundRobinProxySwitcher(a...) if err != nil {
log.Fatal(err)
}
c.SetProxyFunc(rp) c.OnHTML("a[href]", func(e *colly.HTMLElement) {
link := e.Attr("href")
fmt.Printf("Link found: %q -> %s\n", e.Text, link)
c.Visit(e.Request.AbsoluteURL(link))
})
c.OnRequest(func(r *colly.Request) {
fmt.Println("Visiting", r.URL.String())
r.Headers.Set("User-Agent", pTool.RandomString())
})
c.Visit("http://cn.sonhoo.com/wukong/a58627") } 动态更新代理ip,实时使用

go colly proxy 代理ip 动态 ip的更多相关文章

  1. java中Proxy(代理与动态代理)

    转自: https://blog.csdn.net/pangqiandou/article/details/52964066 一.代理的概念 动态代理技术是整个java技术中最重要的一个技术,它是学习 ...

  2. 二、Linux 静态IP,动态IP配置

    Linux 静态IP,动态IP配置 第一步:激活网卡 系统装好后默认的网卡是eth0,用下面的命令将这块网卡激活. # ifconfig eth0 up 第二步:设置网卡进入系统时启动 想要每次开机就 ...

  3. 实体ip 虚拟ip 固定ip 动态ip

    实体 IP:在网络的世界里,为了要辨识每一部计算机的位置,因此有了计算机 IP 位址的定义.一个 IP 就好似一个门牌!例如,你要去微软的网站的话,就要去『 207.46.197.101 』这个 IP ...

  4. Linux 静态IP动态IP设置

    1.设置动态IP ifconfig eth0 192.168.1.12 设置后立即生效,重启机器后就无效了 2.设置静态IP 编辑文件 /etc/sysconfig/network-scripts/i ...

  5. Proxy 代理模式 动态代理 CGLIB

    代理的基本概念 几个英文单词: proxy [ˈprɒksi] n. 代理服务器:代表权:代理人,代替物:委托书: invoke [ɪnˈvəʊk] vt. 乞灵,祈求:提出或授引-以支持或证明:召鬼 ...

  6. Proxy 代理模式 动态代理 cglib MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  7. 设置Windows静态IP+动态IP

    静态IP 设置以太网属性 进入IPv4属性 设置IPv4 动态IP 同上方法,只不过选成了自动

  8. python + seleinum +phantomjs 设置headers和proxy代理

    python + seleinum +phantomjs 设置headers和proxy代理     最近因为工作需要使用selenium+phantomjs无头浏览器,其中遇到了一些坑,记录一下,尤 ...

  9. nodejs爬虫如何设置动态ip以及userAgent

    nodejs爬虫如何设置动态ip以及userAgent 转https://blog.csdn.net/u014374031/article/details/78833765 前言 在写nodejs爬虫 ...

随机推荐

  1. Cocos 2d-X Lua游戏开发Mac环境搭建以及一点点感悟

    接触Cocos2d-x 最近由于公司项目的需要,自己开始接触Cocos,开始做一些简单的轻量级的游戏,以前没有接触过这一块的东西,也是借助这个机会学习一下游戏的开发,由于以前自己接触的全都是iOS和A ...

  2. codevs——2853 方格游戏(棋盘DP)

    时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解  题目描述 Description 菜菜看到了一个游戏,叫做方格游戏~ 游戏规则是这样的: 在一个n*n的 ...

  3. TIOBE排行榜

    作者:码思客链接:https://zhuanlan.zhihu.com/p/37513668来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 1 JAVA 毫无疑问的业界 ...

  4. 基于WPF系统框架设计(7)-TextBox/PasswordBox在ViewModel中支持回车命令

    应用场景 我现在做一个系统登录功能,要求在PasswordBox上输完密码后回车,能够响应Enter事件,并执行ViewModel中对应的方法.如果登录成功则隐藏当前窗口显示主窗体,登录失败则焦点返回 ...

  5. pair类型

    pair是一个模板数据类型,其中包含两个数据值,两个数据值可以不同 如 pair<int,string>a(2,"fgh");则a是一个pair类型,它包括两个数据,第 ...

  6. mac 安装 word2016并破解

    http://blog.csdn.net/zqbx7/article/details/53448280

  7. 细微之处见功夫!这5点让Wish3D Earth与众不同

    产品的体验是全方位的,任何一点,都可能决定成败.细微之处见功夫,5个细节,告诉你Wish3D Earth为什么与众不同. 中科图新最新发布的Wish3D Earth,是基于WebGL技术的网页版三维地 ...

  8. StringUtils和IOUtils工具包的使用

    加载apache的工具类 <dependency> <groupId>commons-lang</groupId> <artifactId>common ...

  9. 使用Shiro

    一.架构 要学习如何使用Shiro必须先从它的架构谈起,作为一款安全框架Shiro的设计相当精妙.Shiro的应用不依赖任何容器,它也可以在JavaSE下使用.但是最常用的环境还是JavaEE.下面以 ...

  10. C 位域

    C 位域 如果程序的结构中包含多个开关量,只有 TRUE/FALSE 变量,如下: struct { unsigned int widthValidated; unsigned int heightV ...