刷文章访问量

#引入必需的模块
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
 
links=['https://www.jianshu.com/p/0da443d63bab','https://www.jianshu.com/p/aa89c4be9e43','https://www.jianshu.com/p/f0dcfc9cc620','https://www.jianshu.com/p/2202fb842e02','https://www.jianshu.com/p/edb79e301468','https://www.jianshu.com/p/48aa52887c9f','https://www.jianshu.com/p/97ef46be1582'] 
llen=len(links)

#选项
chrome_options=Options()
 
 
#设置chrome浏览器为无界面模式
chrome_options.add_argument('--headless')
 
 
 
#下面的两行代码一般是不需要的,至少经过我的测试在windows上是不需要的。但经过我的测试在Ubuntu上如果不加的话等下就会报错WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser,所以要加上
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
 

#获取我的文章的标题
#browser = webdriver.Chrome(options=chrome_options)
#browser.get('https://www.jianshu.com/p/0da443d63bab')
#print(browser.title)
i=0
browser = webdriver.Chrome(options=chrome_options)

while i<1000:
    for j in range(1,llen):
        browser.get(links[j-1])
        print(browser.title)
    i+=1
    

安装模块引自https://blog.youkuaiyun.com/shjsfx/article/details/106006255

多线程

#引入必需的模块
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import _thread
 

     
 
links=['https://www.jianshu.com/p/0da443d63bab','https://www.jianshu.com/p/aa89c4be9e43','https://www.jianshu.com/p/f0dcfc9cc620','https://www.jianshu.com/p/2202fb842e02','https://www.jianshu.com/p/edb79e301468','https://www.jianshu.com/p/48aa52887c9f','https://www.jianshu.com/p/97ef46be1582'] 
llen=len(links)


#选项
chrome_options=Options()
 
 
#设置chrome浏览器为无界面模式
chrome_options.add_argument('--headless')
 
 
 
#下面的两行代码一般是不需要的,至少经过我的测试在windows上是不需要的。但经过我的测试在Ubuntu上如果不加的话等下就会报错WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser,所以要加上
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
 
#来自 https://blog.youkuaiyun.com/shjsfx/article/details/106006255 

#获取我的文章的标题
#browser = webdriver.Chrome(options=chrome_options)
#browser.get('https://www.jianshu.com/p/0da443d63bab')
#print(browser.title)

def thr(thnum):
    i=0
    browser = webdriver.Chrome(options=chrome_options)
    while i<1000:
        for j in range(0,llen):
            browser.get(links[j])
            print(thnum," ",i," ",j)
    i+=1

try:
    _thread.start_new_thread(thr,(1,))
    _thread.start_new_thread(thr,(2,))
    _thread.start_new_thread(thr,(3,))
    _thread.start_new_thread(thr,(4,))
except:
    print ("Error:无法启动线程")

#while i<1000:
#    for j in range(0,llen):
#        browser.get(links[j])
#        print(browser.title)
#    i+=1
while 1:
    pass
    
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值