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_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
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.csdn.net/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_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
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 1:
pass