QWebview:上传到 Youtube 返回错误 [英] QWebview: Upload to Youtube return error
本文介绍了QWebview:上传到 Youtube 返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的情况:我创建了一个 QWebview,加载了一个 Youtube 页面,然后登录.我选择上传选项 (http://www.youtube.com/my_videos_upload),然后选择要上传的视频.但是,youtube总是返回
Here is my situation: I have created a QWebview, loaded a Youtube page, and logged in. I select upload option (http://www.youtube.com/my_videos_upload), and choose a video to upload. However, youtube always returns
服务器返回了无效响应.请按照以下步骤操作,然后再次尝试上传文件."
"The server has returned an invalid response. Please follow these steps and try uploading the file again."
我该如何解决这个问题?谢谢.
How can I solve that problem? Thanks.
我使用的代码是:
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_()
推荐答案
尝试在 web = QWebView()
之后添加:
settings = web.settings()
settings.setAttribute(QWebSettings.PluginsEnabled, True)
这篇关于QWebview:上传到 Youtube 返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文