Python—selenium爬取快代理

本文利用selenium技术爬取快代理网站上的代理IP,并通过验证筛选出可用的代理。爬取了十页代理后,对获取的IP进行有效性检查。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本篇使用 selenium技术 爬取快代理上的代理IP,并判断其是否可用。

#爬取代理IP

from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType
from selenium.webdriver.common import desired_capabilities
import time
from random import randint
from bs4 import BeautifulSoup
import pymysql

'''
PhantomJS常用配置
'''
#增加头信息
headers = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 
    "Accept-Language": "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3",
    'Accept-Charset': 'utf-8',
    "User-Agent": "Mozilla/5.0 (Windows NT 6.2; WOW64;rv:47.0) Gecko/20100101 Firefox/47.0",
    "Host": "www.kuaidaili.com",
    "Connection": "keep-alive"
}

#DesiredCapabilities 手动设置爬取时你所期望的功能配置
for key in headers:
    webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.{}'.format(key)] = headers[key]
proxy=Proxy(
    {
        'proxyType':ProxyType.MANUAL,    #manual 手工的,手动的
        'h
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值