2016-06-14 60 views
2

现在,我开始一个Python项目,该项目应该对选定的twitch频道进行截图,修改这些截图并将其放在GUI上。图形用户界面不应该是一个问题,但我的屏幕截图有问题。
我发现了2个资源来处理twitch通信:python-twitch包和一个名为ttvsnap的脚本(https://github.com/chfoo/ttvsnap)。
这个软件包对我没有任何帮助,因为我没有找到任何与屏幕截图相关的东西。该脚本看起来很有前途,但是我遇到了一些问题:使用Python从Twitch抓取屏幕截图

根据创建者的说法,ttvsnap会定期截取一个抽搐流并将它们放入选定的目录中。
如果我尝试启动脚本,我得到这个错误:从剧本

Traceback (most recent call last): 
    File "ttvsnap.py", line 13, in <module> 
     import requests 
ImportError: No module named 'requests' 

擦除“导入请求”让我来运行它,但随后的脚本与选择问题目录。要运行脚本,我应该写:

Python ttvsnap.py 'streamname here' 'directory here' 

从创作者的例子目录是“./screenshot/”,但与投入,我发现了以下错误(也许是因为我” M于Windows)中:

Output directory specified is not valid. 

试图像C目录:\ DevFiles \截图给我下面的错误:

Invalid drive specification. ###Translated this line since I'm using a German OS 
Traceback (most recent call last): 
    File "ttvsnap.py", line 176, in <module> 
    main() 
    File "ttvsnap.py", line 46, in main 
    subprocess.check_call(['convert', '-version']) 
    File "C:\Program Files (x86)\Python35-32\lib\subprocess.py", line 584, in check_call 
    raise CalledProcessError(retcode, cmd) 
subprocess.CalledProcessError: Command '['convert', '-version']' returned non-zero exit status 4 

如何得到它运行任何想法或不同的资源使用将非常感激。

+1

你有没有试过'PIP安装requests'?它不是标准库的一部分。 – jonrsharpe

回答

0

Selenium可以方便地浏览网站并截取屏幕截图。

http://selenium-python.readthedocs.io/

跃然纸上应该做你需要的例子。 吉斯特链接,以及: https://gist.github.com/ryantownshend/6449c4d78793f015f3adda22a46f1a19

""" 
basic example. 

Dirt simple example of using selenium to screenshot a site. 

Defaults to using local Firefox install. 
Can be setup to use PhantomJS 

http://phantomjs.org/download.html 

This example will run in both python 2 and 3 
""" 
import os 
from selenium import webdriver 
from selenium.webdriver.common.by import By 
from selenium.webdriver.common.keys import Keys 
from selenium.webdriver.support import expected_conditions as EC 
from selenium.webdriver.support.ui import WebDriverWait 


def main(): 
    """the main function.""" 
    driver = webdriver.Firefox() 
    # driver = webdriver.PhantomJS() 
    driver.get("http://google.com") 
    # assert "Python" in driver.title 
    elem = driver.find_element_by_name("q") 
    elem.clear() 
    elem.send_keys("cats") 
    elem.send_keys(Keys.RETURN) 

    # give the query result time to load 
    WebDriverWait(driver, 10).until(
     EC.visibility_of_element_located((By.ID, "resultStats")) 
    ) 

    # take the screenshot 
    pwd = os.path.dirname(os.path.realpath(__file__)) 
    driver.save_screenshot(os.path.join(pwd, 'cats.png')) 
    driver.close() 

if __name__ == '__main__': 
    main() 
+0

为我的目的,是否有任何硒(如ImageMagick)必需品或我安装包后我很好去? – Hillburn

+0

更新了帖子,为您举例。 –

+0

谢谢,这个例子适用于PhantomJS。但是,我是Python的新手,所以我不完全了解如何设置屏幕截图的目标。 “__ file __”变量引用的是包含脚本本身的文件吗? – Hillburn

1

您不应该从您尝试使用的开源项目中删除项目。

相反,安装缺少的包,

pip install requests如果你有一个问题,也许你没有pip,所以才安装它。使用此python.exe -m pip install requests


此错误Output directory specified is not valid.是由于这一行:

if not os.path.isdir(args.output_dir): 
    sys.exit('Output directory specified is not valid.') 

这通常意味着目录不存在


至于最后一个错误,不能执行该命令convert

Invalid drive specification. ###Translated this line since I'm using a German OS 
Traceback (most recent call last): 
    File "ttvsnap.py", line 176, in <module> 
    main() 
    File "ttvsnap.py", line 46, in main 
    subprocess.check_call(['convert', '-version']) 
    File "C:\Program Files (x86)\Python35-32\lib\subprocess.py", line 584, in check_call 
    raise CalledProcessError(retcode, cmd) 
subprocess.CalledProcessError: Command '['convert', '-version']' returned non-zero exit status 4 

这只是意味着你没有安装Imagemagick做。您可以通过下载正确安装你的架构在这里安装:http://www.imagemagick.org/script/binary-releases.php

然后用这些选项打勾安装: enter image description here

然后尝试,并确保该convert命令从终端执行。如果没有,请按照以下说明操作:

Lastly you have to set MAGICK_HOME environment variable to the path of ImageMagick (e.g. C:\Program Files\ImageMagick-6.7.7-Q16). You can set it in Computer ‣ Properties ‣ Advanced system settings ‣ Advanced ‣ Environment Variables....

source

+0

已安装的请求,现在我不必再从脚本中删除它了,但我仍然收到与之前一样的错误消息 – Hillburn

+0

@Hillburn您是否创建了该文件夹?它目前是否存在? – majidarif

+0

@Hillburn尝试使用'python3 ttvsnap.py verycoolstreamer ./ screenshots /',但要确保运行脚本的当前目录中存在“screenshots”目录。 – majidarif