我试图让我的脚本从www.subscene.com下载字幕。问题是,网页上的下载按钮是用java制作的,出于某种原因,即使我提取URL,我也无法下载字幕。Python:从javascript获得下载链接按钮
我认为这是对的下载按钮的代码:
<a id="s_lc_bcr_downloadLink" class="downloadLink rating0" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("s$lc$bcr$downloadLink", "", true, "", "/english/How-I-Met-Your-Mother-Seventh-Season/subtitle-482407-dlpath-90698/zip.zipx", false, true))">Download English Subtitle</a><a id="s_lc_bcr_previewLink" href="javascript:togglePreview(482407, 'zip');">(See preview)</a>
,所以我提取的网址,并告诉我的脚本下载:
urllib.urlretrieve('http://subscene.com/english/How-I-Met-Your-Mother-Seventh-Season/subtitle-482407-dlpath-90698/zip.zipx','c:\\sub.zip')
(新增的“http://子场景.com')
但由于某种原因,它不下载正确的文件。我应该做些什么?
编辑:
非常感谢!遗憾的是我不能让它的工作:(它说以下
from selenium import webdriver
browser = webdriver.Firefox()
browser.execute_script('WebForm_DoPostBackWithOptions(newWebForm_PostBackOptions("s$lc$bcr$downloadLink", "", true, "", "/english/How-I-Met-Your-Mother-Seventh-Season/subtitle-482407-dlpath-90698/zip.zipx", false, true))')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
browser.execute_script('WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("s$lc$bcr$downloadLink", "", true, "", "/english/How-I-Met-Your-Mother-Seventh-Season/subtitle-482407-dlpath-90698/zip.zipx", false, true))')
File "C:\Users\User\AppData\Roaming\Python\Python27\site-packages\selenium\webdriver\remote\webdriver.py", line 385, in execute_script{'script': script, 'args':converted_args})['value']
File "C:\Users\User\AppData\Roaming\Python\Python27\site-packages\selenium\webdriver\remote\webdriver.py", line 153, in execute
self.error_handler.check_response(response)
File "C:\Users\User\AppData\Roaming\Python\Python27\site-packages\selenium\webdriver\remote\errorhandler.py", line 126, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: ''
你的努力下载(zip.zipx)不是文件,这就是一些JavaScript。我正在研究如何获得下载的网址。 –
这将很难找到每个文件的实际URL。它似乎一切都从服务器通过JavaScript检索。我认为这不是一个网址,也许是本地目录,你将不得不好好看看网站的JavaScript以及它如何处理这些文件。我注意到'http://subscene.com/downloadissue.aspx?subtitleId = 482407&contentType = zip'这一行很多,这意味着它找到了'subtitleId',然后确保'zip'的'contentType',并从那里抓取它。这可能是用SQL的一种形式组织的。 –