go colly proxy 代理ip 动态 ip
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的更多相关文章
- java中Proxy(代理与动态代理)
转自: https://blog.csdn.net/pangqiandou/article/details/52964066 一.代理的概念 动态代理技术是整个java技术中最重要的一个技术,它是学习 ...
- 二、Linux 静态IP,动态IP配置
Linux 静态IP,动态IP配置 第一步:激活网卡 系统装好后默认的网卡是eth0,用下面的命令将这块网卡激活. # ifconfig eth0 up 第二步:设置网卡进入系统时启动 想要每次开机就 ...
- 实体ip 虚拟ip 固定ip 动态ip
实体 IP:在网络的世界里,为了要辨识每一部计算机的位置,因此有了计算机 IP 位址的定义.一个 IP 就好似一个门牌!例如,你要去微软的网站的话,就要去『 207.46.197.101 』这个 IP ...
- Linux 静态IP动态IP设置
1.设置动态IP ifconfig eth0 192.168.1.12 设置后立即生效,重启机器后就无效了 2.设置静态IP 编辑文件 /etc/sysconfig/network-scripts/i ...
- Proxy 代理模式 动态代理 CGLIB
代理的基本概念 几个英文单词: proxy [ˈprɒksi] n. 代理服务器:代表权:代理人,代替物:委托书: invoke [ɪnˈvəʊk] vt. 乞灵,祈求:提出或授引-以支持或证明:召鬼 ...
- Proxy 代理模式 动态代理 cglib MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- 设置Windows静态IP+动态IP
静态IP 设置以太网属性 进入IPv4属性 设置IPv4 动态IP 同上方法,只不过选成了自动
- python + seleinum +phantomjs 设置headers和proxy代理
python + seleinum +phantomjs 设置headers和proxy代理 最近因为工作需要使用selenium+phantomjs无头浏览器,其中遇到了一些坑,记录一下,尤 ...
- nodejs爬虫如何设置动态ip以及userAgent
nodejs爬虫如何设置动态ip以及userAgent 转https://blog.csdn.net/u014374031/article/details/78833765 前言 在写nodejs爬虫 ...
随机推荐
- HDU 1022 Train Problem I[给出两个长n的串,入栈和出栈顺序,判断入栈顺序是否可以匹配出栈顺序]
Train Problem I 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 As the new term comes, the Ignatius Train Sta ...
- CodeForces - 258D Little Elephant and Broken Sorting
Discription The Little Elephant loves permutations of integers from 1 to n very much. But most of al ...
- Eclipse 最常用的 10 组快捷键,个个牛逼!
虽然栈长我现在不怎么用 Eclipse 了,但 Eclipse 的快捷键还是忘不了的,可以说 Eclipse 的快捷键很方便,恰到好处. 今天,我大概整理了 10 组 Eclipse 我觉得比较常用的 ...
- Data structure basics - Java Implementation
Stack & Queue Implementations FixedCapacityQueue package cn.edu.tsinghua.stat.mid_term; import j ...
- mysql忘记密码的解决办法
mysql忘记密码时,需要重设密码. 在Windows下的操作如下: 1.关闭正在运行的MySQL. 2.打开DOS窗口,转到mysql\bin目录. 3.输入mysqld --skip-grant- ...
- Hadoop部署启动异常问题排查
hadoop的日志目录(/home/hadoop/app/hadoop-2.6.4/logs) 1.hadoop启动不正常用浏览器访问namenode的50070端口,不正常,需要诊断问题出在哪里: ...
- C 递归 递归指的是在函数的定义中
C 递归 递归指的是在函数的定义中使用函数自身的方法. 举个例子:从前有座山,山里有座庙,庙里有个老和尚,正在给小和尚讲故事呢!故事是什么呢?"从前有座山,山里有座庙,庙里有个老和尚,正在给 ...
- 应该知道的Linux技巧(转载)
这篇文章来源于Quroa的一个问答<What are some time-saving tips that every Linux user should know?>—— Linux用户 ...
- Sereja and Array-数组操作或者线段树或树状数组
CodeForces - 315B Sereja and Array Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I ...
- mybatis性能优化之降低数据库连接
做性能优化的最重要的功能就是降低数据库的交互.非常多程序猿一般在开发的时候仅仅考虑简单的实现功能,无论业务简单复杂,仅仅要实现即可. mybatis有个重要的功能就是考虑在联合查询时技巧: <? ...