2010-04-30 2 views
2

나는 스크린 샷해야하는 많은 호스트로부터 수천 개의 URL을 얻었습니다.python-webkit2png을 사용하여 동시에 많은 스크린 샷을 찍는 방법은 무엇입니까?

명령 줄에서 lib를 잘 사용할 수는 있지만 동시에 여러 스크린 샷을 찍을 수 있도록 어떻게 코드를 통합 할 수 있습니까?

이 질문에 대한 답변과 마찬가지로 xvfb와 관련이 있다고 생각합니다. How to kill headless X server started via Python?하지만 정확히 무엇이 정확한지는 잘 모르겠습니다.

답변

0

이 (테스트되지 않은) 같은 아마 뭔가가 :

from webkit2png import WebkitRenderer, init_qtgui 
from PyQt4.QtCore import QTimer 

def renderer_func(): 
    renderer = WebkitRenderer() 
    renderer.width = 800 
    renderer.height = 600 
    renderer.timeout = 10 
    renderer.wait = 1 
    renderer.format = "png" 
    renderer.grabWholeWindow = False 

    outfile = open("stackoverflow.png", "w") 
    renderer.render_to_file(url="http://stackoverflow.com", file=outfile) 
    outfile.close() 

app = init_qtgui() 
QTimer.singleShot(0, renderer_func) 
sys.exit(app.exec_()) 

이 뻔뻔 source code of webkit2png.py에서 찢어졌다.

+0

감사합니다. 문제가있는 부분은 Xvfb – oldfellow

0

subprocess을 사용하여 python-webkit2png을 통해 설치된 webkit2png을 호출하면 이 정상적으로 작동합니다.

def scrape_url(url, outpath): 
    """ 
    Requires webkit2png to be on the path 
    """ 
    subprocess.call(["webkit2png", "-o", outpath, "-g", "1000", "1260", 
        "-t", "30", url]) 

def scrape_list_urls(list_url_out_name, outdir): 
    """ 
    list_url_out_name is a list of tuples: (url, name) 
    where name.png will be the image's name 
    """ 
    count = 0 
    for url, name in list_url_out_name: 
     print count 
     count += 1 
     outpath = outdir + name + '.png' 
     scrape_url(url, outpath) 
관련 문제