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爬虫 ...
随机推荐
- PostMan的在线安装和简单使用
Postman是一款很流行的WEB接口测试工具,因其强大的功能及清新的界面,赢得许多测试及开发者的喜爱. 1.PostMan的在线安装 因google退出中国,使得chrome上的扩展插件无法在线 ...
- [深度应用]·Keras实现Self-Attention文本分类(机器如何读懂人心)
[深度应用]·Keras实现Self-Attention文本分类(机器如何读懂人心) 配合阅读: [深度概念]·Attention机制概念学习笔记 [TensorFlow深度学习深入]实战三·分别使用 ...
- CodeForces - 16E Fish
Discription n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and ...
- [转] VS2015中跑OpenGL红宝书第八版的第一章示例代码,运行
Ori Article Link OpenGL的东西快忘光了,把角落的第八版红宝书拿出来复习一下 从书中的地址下了个示例代码结果新系统(Win10+VS2015)各种跑不起来,懊恼之后在网上疯狂搜索资 ...
- PHP生成月历代码
<?php /* Function Written by Nelson Neoh @3/2004. For those who wants to utilize this code, p ...
- css样式大全(整理版)
字体属性:(font) 大小 {font-size: x-large;}(特大) xx-small;(极小) 一般中文用不到,只要用数值就可以,单位:PX.PD 样式 {font-style: obl ...
- 【Web API系列教程】1.2 — Web API 2中的Action Results
前言 本节的主题是ASP.NET Web API怎样将控制器动作的返回值转换成HTTP的响应消息. Web API控制器动作能够返回下列的不论什么值: 1. void 2. HttpResponseM ...
- MongoDB基本文件操作
MongoDB中主要的文件操作有put.get.list.search几种.能够非常方便地进行文件存储于查找,下面是一个简单的演示样例. 1.利用dd命令生成要求大小随机文件 2.使用put命令将生 ...
- vue prop单向数据流
Prop 是单向绑定的:当父组件的属性变化时,将传导给子组件,但是反过来不会.这是为了防止子组件无意间修改了父组件的状态,来避免应用的数据流变得难以理解. 另外,每次父组件更新时,子组件的所有 pro ...
- Material Design Get Started
使用Material Design设计应用: Take a look at the material design specification. Apply the material theme to ...