0

这是我的情况:我创建了一个 QWebview,加载了一个 Youtube 页面,然后登录。我选择上传选项 (http://www.youtube.com/my_videos_upload),然后选择要上传的视频。但是,youtube 总是返回

“服务器返回了无效响应。请按照以下步骤重新尝试上传文件。”

我该如何解决这个问题?谢谢。

编辑:我使用的代码是:

import sys
from PyQt4.QtCore import QUrl
from PyQt4.QtGui import QApplication
from PyQt4.QtWebKit import QWebView
from PyQt4.QtNetwork import QNetworkAccessManager
from PyQt4 import QtCore

def fillForm(web, username, password):
    print "Filling in the form"
    doc = web.page().mainFrame().documentElement()

    print "Finding username tag"
    user = doc.findFirst("input[id=Email]")
    print "Finding passwd tag"
    passwd = doc.findFirst("input[id=Passwd]")    

    print "Setting information"
    user.evaluateJavaScript("this.value = '%s'" % username)
    passwd.evaluateJavaScript("this.value = '%s'" % password)    
    button = doc.findFirst("input[id=signIn]")
    button.evaluateJavaScript("this.click()")

def doLogin(web, url, username, password):        
    web.loadFinished.connect(lambda: fillForm(web, username, password))
    web.load(url)
    web.show()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    nam = QNetworkAccessManager()
    web = QWebView()
    web.page().setNetworkAccessManager(nam)
    url = QUrl(r"https://accounts.google.com/Login")
    username = "name"
    password = "pass"
    doLogin(web, url, username, password)
    app.exec_()
4

1 回答 1

0

尝试在之后添加web = QWebView()

settings = web.settings()
settings.setAttribute(QWebSettings.PluginsEnabled, True)
于 2012-12-08T14:30:31.017 回答