Показать полную графическую версию : [решено] скачать файл из инета из cgi-bin => location.replace
Читаю файлы из инета. Использовал inetget. Сегодня наткнулся на список ссылок вида:
cgi-bin/viewlist.pl?id=75349
при копировании ссылки в окно firefox она дает окно на загрузку, однако в автоит скаченный файл - html:
window.location.replace("/files/75349.pdf")
Можно как чтобы autoit читал такие файлы с инета? Альтернативно можно писать анализ что если ответ вида .location.replace то повторить скачку с новым адресом. Может все-же это уже реализовано?
Спасибо!
[Сеть, интернет] Как скачать файл с родным именем? (http://autoit-script.ru/index.php?topic=2805.0)
Спасибо! Код интересный и я кое-что оттуда узнал. Однако с моей ссылкой вместо реального пути к файлу функция _HTTPGetResponse возвращает в первой строке "OK" вместо "found", а строки "location:" вовсе нет - поэтому не срабатывает. Интересно почему, кто знает?
Да, на всякий вот полный путь если кто захочет поэкспериментировать:
http://www.lada-auto.ru/cgi-bin/viewlist.pl?id=85544&fld=file_&tbl=vaz_catalogue_notes&ext=pdf
madmasles
24-01-2011, 10:45
AlexM,
С этой ссылкой у меня так скачивает:#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <INet.au3>
$sUrl = 'http://www.lada-auto.ru/cgi-bin/viewlist.pl?id=85544&fld=file_&tbl=vaz_catalogue_notes&ext=pdf'
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) InetGetSize (http://www.autoitscript.com/autoit3/docs/functions/InetGetSize.htm)($sUrl) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$sText = _INetGetSource (http://dundats.mvps.org/help/html/libfunctions/_inetgetsource.htm)($sUrl)
$sFirstPartNewUrl = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($sUrl, '\A(http://.*?/)\w?.*', '\1')
$sSecondPartNewUrl = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($sText, '(?s).*?\("/(.*?)"\)?.*', '\1')
$sFileName = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($sSecondPartNewUrl, '^.*/', '')
$sNewUrl = $sFirstPartNewUrl & $sSecondPartNewUrl
$hDownload = InetGet (http://www.autoitscript.com/autoit3/docs/functions/InetGet.htm)($sNewUrl, @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\' & $sFileName, 1, 1)
Do (http://www.autoitscript.com/autoit3/docs/keywords.htm#Do)
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(20)
Until (http://www.autoitscript.com/autoit3/docs/keywords.htm#Until) InetGetInfo (http://www.autoitscript.com/autoit3/docs/functions/InetGetInfo.htm)($hDownload, 2)
$nBytes = InetGetInfo (http://www.autoitscript.com/autoit3/docs/functions/InetGetInfo.htm)($hDownload, 0)
InetClose (http://www.autoitscript.com/autoit3/docs/functions/InetClose.htm)($hDownload)
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(64, 'OK', 'Скачан файл ' & $sFileName & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@crlf) & ' размером ' & $nBytes & ' b')
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
InetGet (http://www.autoitscript.com/autoit3/docs/functions/InetGet.htm)($sUrl, @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\Test.pdf')
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)Или сразу из ссылки "выдрать" прямую ссылку и скачать по ней:$sUrl = 'http://www.lada-auto.ru/cgi-bin/viewlist.pl?id=85544&fld=file_&tbl=vaz_catalogue_notes&ext=pdf'
$sCatalog = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($sUrl, '\A(http://.*?/)\w?.*fld=(.*?)_&?.*', '\1\2/')
$sFileName = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($sUrl, '(?s).*?id=(.*?)&fld?.*', '\1')
$sExt = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($sUrl, '(?s).*?ext=(.*?)\z', '\1')
$sNewUrl = $sCatalog & $sFileName & '.' & $sExt
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(64, '', 'Прямая ссылка: ' & $sNewUrl & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@crlf) & 'Имя файла: ' & $sFileName & '.' & $sExt)
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.
Available in ZeroNet 1osznRoVratMCN3bFoFpR2pSV5c9z6sTC