vb.net 多线程爬虫抓取免费代理IP
Class Program
Public Shared masterPorxyList As List(Of proxy) = New List(Of proxy)()
Public Class proxy
Public ip As String
Public port As String
Public speed As Integer
Public Sub New(ByVal pip As String, ByVal pport As String, ByVal pspeed As Integer)
Me.ip = pip
Me.port = pport
Me.speed = pspeed
End Sub
End Class
Private Shared Sub getProxyList(ByVal pageIndex As Object)
Dim urlCombin As String = "http://www.xicidaili.com/wt/" & pageIndex.ToString()
Dim catchHtml As String = catchProxIpMethord(urlCombin, "UTF8")
Dim doc As HtmlAgilityPack.HtmlDocument = New HtmlAgilityPack.HtmlDocument()
doc.LoadHtml(catchHtml)
Dim table As HtmlNode = doc.DocumentNode.SelectSingleNode("//div[@id='wrapper']//div[@id='body']/table[1]")
Dim collectiontrs As HtmlNodeCollection = table.SelectNodes("./tr")
For i As Integer = 0 To collectiontrs.Count - 1
Dim itemtr As HtmlAgilityPack.HtmlNode = collectiontrs(i)
Dim collectiontds As HtmlNodeCollection = itemtr.ChildNodes
If i > 0 Then
Dim itemtdip As HtmlNode = CType(collectiontds(3), HtmlNode)
Dim itemtdport As HtmlNode = CType(collectiontds(5), HtmlNode)
Dim itemtdspeed As HtmlNode = CType(collectiontds(13), HtmlNode)
Dim ip As String = itemtdip.InnerText.Trim()
Dim port As String = itemtdport.InnerText.Trim()
Dim speed As String = itemtdspeed.InnerHtml
Dim beginIndex As Integer = speed.IndexOf(":", 0, speed.Length)
Dim endIndex As Integer = speed.IndexOf("%", 0, speed.Length)
Dim subSpeed As Integer = Integer.Parse(speed.Substring(beginIndex + 1, endIndex - beginIndex - 1))
If subSpeed > 90 Then
Dim temp As proxy = New proxy(ip, port, subSpeed)
masterPorxyList.Add(temp)
Console.WriteLine("当前是第:" & masterPorxyList.Count.ToString() & "个代理IP")
End If
End If
Next
End Sub
Private Shared Function catchProxIpMethord(ByVal url As String, ByVal encoding As String) As String
Dim htmlStr As String = ""
Try
If Not String.IsNullOrEmpty(url) Then
Dim request As WebRequest = WebRequest.Create(url)
Dim response As WebResponse = request.GetResponse()
Dim datastream As Stream = response.GetResponseStream()
Dim ec As Encoding = Encoding.[Default]
If encoding = "UTF8" Then
ec = Encoding.UTF8
ElseIf encoding = "Default" Then
ec = Encoding.[Default]
End If
Dim reader As StreamReader = New StreamReader(datastream, ec)
htmlStr = reader.ReadToEnd()
reader.Close()
datastream.Close()
response.Close()
End If
Catch
End Try
Return htmlStr
End Function
Private Shared Sub Main(ByVal args As String())
For i As Integer = 1 To 15
ThreadPool.QueueUserWorkItem(AddressOf getProxyList, i)
Next
Console.Read()
End Sub
End Class
vb.net 多线程爬虫抓取免费代理IP的更多相关文章
- C#多线程爬虫抓取免费代理IP
这里用到一个HTML解析辅助类:HtmlAgilityPack,如果没有网上找一个增加到库里,这个插件有很多版本,如果你开发环境是使用VS2005就2.0的类库,VS2010就使用4.0,以此类推.. ...
- PHP简单爬虫 爬取免费代理ip 一万条
目标站:http://www.xicidaili.com/ 代码: <?php require 'lib/phpQuery.php'; require 'lib/QueryList.php'; ...
- 简单爬虫-爬取免费代理ip
环境:python3.6 主要用到模块:requests,PyQuery 代码比较简单,不做过多解释了 #!usr/bin/python # -*- coding: utf-8 -*- import ...
- c#批量抓取免费代理并验证有效性
之前看到某公司的官网的文章的浏览量刷新一次网页就会增加一次,给人的感觉不太好,一个公司的官网给人如此直白的漏洞,我批量发起请求的时候发现页面打开都报错,100多人的公司的官网文章刷新一次你给我看这个, ...
- golang爬取免费代理IP
golang爬取免费的代理IP,并验证代理IP是否可用 这里选择爬取西刺的免费代理Ip,并且只爬取了一页,爬取的时候不设置useAgent西刺不会给你数据,西刺也做反爬虫处理了,所以小心你的IP被封掉 ...
- 极简代理IP爬取代码——Python爬取免费代理IP
这两日又捡起了许久不碰的爬虫知识,原因是亲友在朋友圈拉人投票,点进去一看发现不用登陆或注册,觉得并不复杂,就一时技痒搞一搞,看看自己的知识都忘到啥样了. 分析一看,其实就是个post请求,需要的信息都 ...
- 码农代理免费代理ip端口字段js加密破解
起因 之前挖过爬取免费代理ip的坑,一个比较帅的同事热心发我有免费代理ip的网站,遂研究了下:https://proxy.coderbusy.com/. 解密 因为之前爬过类似的网站有了些经验,大概知 ...
- Python 爬虫抓取代理IP,并检测联通性
帮朋友抓了一些代理IP,并根据测试联的通性,放在了不通的文件夹下.特将源码分享 注意: 1,环境Python3.5 2,安装BeautifulSoup4 requests 代码如下: 1 2 3 4 ...
- Python多线程爬虫爬取电影天堂资源
最近花些时间学习了一下Python,并写了一个多线程的爬虫程序来获取电影天堂上资源的迅雷下载地址,代码已经上传到GitHub上了,需要的同学可以自行下载.刚开始学习python希望可以获得宝贵的意见. ...
随机推荐
- Codeforces Round #303 (Div. 2)(CF545) E Paths and Trees(最短路+贪心)
题意 求一个生成树,使得任意点到源点的最短路等于原图中的最短路.再让这个生成树边权和最小. http://codeforces.com/contest/545/problem/E 思路 先Dijkst ...
- HBuilder创建app 3
一.Audio 模块实现开启手机摄像头 基于html5 plus http://www.html5plus.org/doc/zh_cn/audio.html 栗子: <!DOCTYPE html ...
- 剖析linux内核中的宏---------container_of
#define container_of(ptr, type, member) ({ \ const typeof(((type *)0)->member) * __mptr = (ptr); ...
- Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n ...
- Linux 动态链接库路径 LD_LIBRARY_PATH
如果遇到一些 .so 缺失问题 把路径添加到这个变量里面就可以了,注意跟PATH的区别 export LD_LIBRARY_PATH= 注意使用 export 否则变量设置成功但是子进程不可见
- Maven 拥有三套相互独立的生命周期:clean、default、site
table th:nth-of-type(1) { width: 70px; } table th:nth-of-type(2) { width: 100px; } 生命周期 目的 包含的阶段 cle ...
- 添加ssh密钥
直接运行ssh-keygen,可以不输入密码 $ ssh-keygen Generating public/private rsa key pair. Enter file in which to s ...
- pycharm初爬虫
今天尝试使用pycharm+beautifulsoup进行爬虫测试.我理解的主要分成了自己写的HTML和百度上的网页两种吧.第一种,读自己写的网页(直接上代码): (主要参考博客:https://bl ...
- vue-quill-editor富文本编辑器,添加了汉化样式却汉化不了
背景 今天在做后台管理系统时,尝试整合 vue-quill-editor 富文本编辑器,整合完成后,想进行汉化,查阅资料发现,只需自己定义样式替换即可. 原因 当进行汉化时,发现样式并没有替换,汉化失 ...
- 【51Nod 1769】Clarke and math2
[51Nod 1769]Clarke and math2 题面 51Nod 题解 对于一个数论函数\(f\),\(\sum_{d|n}f(d)=(f\times 1)(n)\). 其实题目就是要求\( ...