获得了免费的代理列表,那么就有很多事情可以干,比如 , 爬取某个网站并且没有被封IP的风险, 比如, 增加某网站的流量。
完整代码:#coding:utf-8
import urllib2
import urllib
import cookielib
import hashlib
import re
import time
import json
import unittest
from selenium import webdriver
from bs4 import BeautifulSoup
from pip._vendor.distlib._backport.tarfile import TUREAD
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import random
class Spide:
def __init__(self,proxy_ip,proxy_type,proxy_port,use_proxy=False):
print 'using the proxy info :',proxy_ip
self.proxy_ip = proxy_ip
self.proxy_type = proxy_type
self.proxy_port = proxy_port
self.proxy = urllib2.ProxyHandler({proxy_type: proxy_ip+":"+proxy_port})
self.usercode = ""
self.userid = ""
self.cj = cookielib.LWPCookieJar();
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj));
if use_proxy:
self.opener = urllib2.build_opener(self.proxy)
urllib2.install_