我正在尝试从Youtube下载Android开发教程的整个播放列表。所以我使用savefrom生成播放列表以供下载。但问题是我在该播放列表中有很多视频。 所以,我决定编写一个python脚本,以使这项工作更简单。 但问题是它使用Java Script生成链接,所以我无法使用javascript()获取生成的链接
实施例: http://ssyoutube.com/watch?v=AfleuRtrJoA 生成下载链接需要5秒钟。
我想在浏览 5秒后获取页面来源。
对于这种工作,我找到了一个名为selenium的好包。
import time
from selenium import webdriver
def savefromnotnet(url):
browser = webdriver.Firefox() # Get local session of firefox
browser.get(url) # Load page
time.sleep(5) # Let the page load, will be added to the API
return browser.page_source()
source = savefromnotnet("http://ssyoutube.com/watch?v=AfleuRtrJoA")
savefromnotnet
函数打开的Firefox,它会请求url,到目前为止,每件事情都可以。
但是,当我想获取页面源browser.page_source()
时,它会显示以下错误。
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 523, in runfile
execfile(filename, namespace)
File "C:\Users\BK\Desktop\Working Folder\Python Temp\temp.py", line 10, in <module>
source = savefromnotnet("http://ssyoutube.com/watch?v=AfleuRtrJoA")
File "C:\Users\BK\Desktop\Working Folder\Python Temp\temp.py", line 8, in savefromnotnet
return browser.page_source()
TypeError: 'unicode' object is not callable
答案 0 :(得分:2)
以下行发生错误。
return browser.page_source()
我认为括号不需要。
return browser.page_source
答案 1 :(得分:0)
我想不是!
pcode = wdriver.page_source()
是绝对正确的电话。通过python ide中的自动完成。
我有同样的问题。看起来我们需要在某些方面编码页面文本变量,如经典的ANSI