使用爬虫即可快速实现点击文章网页!
代码如下:
from bs4 import BeautifulSoup
import requests
import time
import random
url =('http://blog.csdn.net/googdev/article/details/52575079')
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36 Edg/93.0.961.52"
}
ip_list = ["195.140.226.244:8080","92.207.253.226:38157","119.15.95.158:8080"]#不同IP地址进行点击
count = random.randint(0,5)#randint用于随机秒数,以防反扒机制的检测
for i in range(10000):#点击次数
for y in ip_list:#循环使用IP地址
time.sleep(count)#随机秒数
req = requests.get(url,headers =headers,proxies={"https://":y})
soup = BeautifulSoup(req.text,'lxml')
print ("已经刷取"+str(i+1)+"次")
期间遇到错误:
requests.exceptions.InvalidURL: Proxy URL had no scheme, should start with http:// or https://
意思:
requests.exceptions.InvalidURL:代理URL没有方案,应以http://或https开头://
解决方案:
在proxies处理代理IP时,将"http"或"https"改为"http://"或"https://"
最终运行结果:
ps:
实际结果可能于代码显示运行次数不相同。