起因
一般来说,我们在爬取其他网站的数据的时候,会遇到ip被限制的情况,这时候就需要代理ip池进行处理了。
代码块
我们这里使用了西刺代理池进行模拟,直接上代码:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests, threading, datetime
from bs4 import BeautifulSoup
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# ip清洗
def checkip(targeturl,ip):
proxies = {
"http": "http://"+ip, "https": "http://"+ip} # 代理ip
try:
response=requests.get(url=targeturl, verify=False, proxies=proxies,headers={
'User-Agent'