爬取免費的IP位址

2021-10-01 17:21:04 字數 3072 閱讀 5561

要是有錢買好的ip**,誰還爬ip位址啊,有錢人請繞路;

資料是存在於mogodb資料庫,開了三個執行緒,我覺得夠了

import requests

from bs4 import beautifulsoup

import time

import pymongo

import random

import threading

deftest1

(urls1)

:for url in urls1:

x = random.choice(iplist)

proxies =

try:

resp = requests.get(url, proxies=proxies, headers=headers)

if resp.status_code ==

200:

soup = beautifulsoup(resp.text,

'lxml'

) trs = soup.find(

'tbody'

).find_all(

'tr'

)for tr in trs:

ipx = tr.find_all(

'td')[

0].string

portx = tr.find_all(

'td')[

1].string

obj =

collections.insert(obj)

print

("success"

)except connectionerror:

print

("失敗了"

)def

test2

(urls2)

:for url in urls2:

x = random.choice(iplist)

proxies =

try:

resp = requests.get(url, proxies=proxies, headers=headers)

if resp.status_code ==

200:

soup = beautifulsoup(resp.text,

'lxml'

) trs = soup.find(

'tbody'

).find_all(

'tr'

)for tr in trs:

ipx = tr.find_all(

'td')[

0].string

portx = tr.find_all(

'td')[

1].string

obj =

collections.insert(obj)

print

("success"

)except connectionerror:

print

("失敗了"

)def

test3

(urls3)

:for url in urls3:

x = random.choice(iplist)

proxies =

try:

resp = requests.get(url, proxies=proxies, headers=headers)

if resp.status_code ==

200:

soup = beautifulsoup(resp.text,

'lxml'

) trs = soup.find(

'tbody'

).find_all(

'tr'

)for tr in trs:

ipx = tr.find_all(

'td')[

0].string

portx = tr.find_all(

'td')[

1].string

obj =

collections.insert(obj)

print

("success"

)except connectionerror:

print

("失敗了"

)client= pymongo.mongoclient(

'localhost'

,27017

)db = client.myip

collections = db.myip

urls1 =

urls2 =

urls3 =

for i in

range

(1200):

''.format

(i +

500)

)for i in

range

(1700):

''.format

(i +

1200))

for i in

range

(3000):

''.format

(i +

2000))

headers =

p = collections.find(

)iplist =

list

(p)t1 = threading.thread(target=test1(urls1)

)t1.start(

)t2 = threading.thread(target=test2(urls2)

)t2.start(

)t3 = threading.thread(target=test3(urls3)

)t3.start(

)ipx = trs.find_all(

'td')[

0].string

portx = trs.find_all(

'td')[

1].string

obj =

collections.insert(obj)

# print(trs)

使用python爬取免費IP並驗證

人生苦短,我用python 1全部 import requests import re 目標位址 get請求到的資料 response requests.get url,headers headers 獲取源 html response.text re.s換行的干擾 正則匹配到源 中的ip和埠 ip...

SQL中取IP位址

該方法查自網上,實際運用過程中,可根據實際情況修改 以下是根據spid獲取ipaddress create proc sp get hostip spid int null as set nocount on declare host varchar 100 declare ip varchar 1...

懶貓隨緣記 今天寫了個ip位址爬取的小爬蟲,菜。

檔案的 如下 import time import random from bs4 import beautifulsoup import csv import requests import pandas as pd from ip位址爬取策略 未完成.headers import get use...