日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

python多线程实现访问页面_python 多线程实现网页自动截图

發(fā)布時(shí)間:2025/3/21 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python多线程实现访问页面_python 多线程实现网页自动截图 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

準(zhǔn)備工作

安裝selenium 2.48.0,一定不要安裝最新版本的,最新版本不支持phantomjs。

用phantomjs是因?yàn)樗菃挝募妗O螺d地址:https://phantomjs.org/download.html

ip.txt的格式是 http://test.com(可根據(jù)需求自行更改)

完整代碼

#!/usr/bin/env python

# -*- coding: utf-8 -*-

# @Time : 2020/8/3 16:10

# @Author : oliver

# @File : test.py

# @Software: PyCharm

import threading

import queue

import time

from selenium import webdriver

class get_screen(threading.Thread):

def __init__(self,q):

super(get_screen,self).__init__()

self.q = q

def run(self):

while not self.q.empty():

url = self.q.get()

try:

self.getScreen(url)

except:

pass

def getScreen(self,url):

brower = webdriver.PhantomJS(executable_path=r"E:\phantomjs-2.1.1-windows\bin\phantomjs.exe")

brower.get(url=url)

brower.maximize_window()

name = url.split("//")[1]

picName = name + ".jpg"

brower.save_screenshot(picName)

brower.close()

def main():

q = queue.Queue()

thread_count =3

threads =[]

with open("ip.txt") as f:

for line in f:

line = line.strip("\n")

q.put(line)

for i in range(thread_count):

# print i

threads.append(get_screen(q))

for thread in threads:

thread.start()

for thread in threads:

thread.join()

if __name__ == '__main__':

start_time = time.time()

main()

print("截圖完成,用時(shí):%f" % (time.time() - start_time))

總結(jié)

以上是生活随笔為你收集整理的python多线程实现访问页面_python 多线程实现网页自动截图的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。