我遇到的问题与以下标题的旧帖子完全相似:
VBA从网站插入.csv,.csv不在网址
如果你能在解决我的问题之前先看看这篇文章,那就太棒了。
我需要编写一个VBA代码来下载网站上的Excel文件(如下)。我找不到上面提到的帖子中描述的确切.csv网址。
网站需要用户名和密码,如果需要,我不介意分享。
请查看以下链接。该文件位于表格的右上角(箭头指向下方):
https://www.oceanschedules.com/schedules/schedule-search.do?&originId=230866&destinationId=100166&weeksOut=6&date=06-May-2014&origin=New York,New York,United States(USNYC)& destination = Alexandria,Egypt(EGALY)& searchType = 0& searchSort = 2& showSurroundingPorts = Y& lad = 05/06 / 2014& dad = 06 /二千零十四分之十七&安培; ISP = 1&安培; PInUserRole = SchedulesInquiry&安培; PInUserType =公共&安培; PInINTTRAProduct =安培; carrierScac =
有什么想法吗?
答案 0 :(得分:0)
我无法为您提供VBA的具体答案,但我可以让您大致了解您需要做什么。
首先关闭 - 您需要获取上面发布的链接的页面内容,作为字符串。在该页面中 - 在第68行附近,是一个JSON对象,其中包含搜索结果的所有数据,存储在变量“aco”中。
然后你需要解析那个JSON以便你可以使用它 - 再次,不确定VBA是否有一个方法 - 但我想它应该。从那里,您可以根据需要使用该数据。如果您的目标是仍然获取xls文件,那么事情会变得更有趣。
生成xls文件的JSP位于https://www.oceanschedules.com/schedules/downloadschedule.do 您需要发送POST请求,并为其提供以下信息
csvResults是一个字符串,由服务器页面用于生成xls文件的逗号分隔值组成。它似乎包括某种程度的格式,这应该是什么样的:
HAPAG-LLOYD***CMA CGM EIFFEL***4215***9248112***Wed***07-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***27***Tue***03-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||CMA CGM***CMA CGM EIFFEL***INA62E***9248112***Thu***08-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***23***Sat***31-May-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||DELMAS***CMA CGM EIFFEL***INA62E***9248112***Thu***08-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***23***Sat***31-May-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***SEASPAN DALIAN***04E19***9227027***Fri***09-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***46***Tue***24-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||MSC***MSC DYMPHNA***NU418R***9110391***Sat***10-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***28***Sat***07-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAMBURG SÜD***FRANKFURT EXPRESS***417E***9450442***Mon***12-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***32***Fri***13-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAMBURG SÜD***FRANKFURT EXPRESS***417W***9450442***Mon***12-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***34***Sun***15-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||ALIANÇA***SEASPAN HAMBURG***415E***9224300***Mon***12-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***47***Sat***28-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAMBURG SÜD***SEASPAN HAMBURG***415E***9224300***Mon***12-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***47***Sat***28-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***MAERSK BATUR***419S***9402029***Mon***12-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***73***Thu***24-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||MAERSK LINE***MAERSK UTAH***1407***9305300***Tue***13-May-2014***NEWARK, NEW JERSEY, UNITED STATES***USEWR***29***Thu***12-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||CMA CGM***OOCL KOBE***INA64E***9329526***Wed***14-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***24***Sat***07-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||DELMAS***OOCL KOBE***INA64E***9329526***Wed***14-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***24***Sat***07-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***OOCL KOBE***4216***9329526***Wed***14-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***27***Tue***10-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAMBURG SÜD***NAGOYA EXPRESS***418E***9450428***Thu***15-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***36***Fri***20-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***SANTA ROBERTA***04E20***9227326***Fri***16-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***46***Tue***01-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||MSC***MSC CAROLE***NU419R***8618308***Sat***17-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***28***Sat***14-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***SPIRIT OF SINGAPORE***420S***9362396***Mon***19-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***73***Thu***31-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||MAERSK LINE***MAERSK DENPASAR***1407***9348663***Tue***20-May-2014***NEWARK, NEW JERSEY, UNITED STATES***USEWR***29***Thu***19-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAMBURG SÜD***WESTERMOOR***419E***9222106***Wed***21-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***30***Fri***20-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***SEASPAN HAMBURG***03E21***9224300***Fri***23-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***46***Tue***08-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||MSC***MSC ILONA***NU420R***9225641***Sat***24-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***28***Sat***21-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||CMA CGM***JPO LIBRA***INA66E***9297840***Sun***25-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***22***Mon***16-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||DELMAS***JPO LIBRA***INA66E***9297840***Sun***25-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***22***Mon***16-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***JPO LIBRA***4217***9297840***Sun***25-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***23***Tue***17-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***MAERSK BRANI***421S***9409352***Mon***26-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***73***Thu***07-Aug-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||MAERSK LINE***MAERSK WISCONSIN***1407***9193252***Tue***27-May-2014***NEWARK, NEW JERSEY, UNITED STATES***USEWR***29***Thu***26-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAMBURG SÜD***KUALA LUMPUR EXPRESS***420E***9343730***Tue***27-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***31***Fri***27-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||CMA CGM***DUBAI EXPRESS***INA68E***9301782***Wed***28-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***26***Mon***23-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||DELMAS***DUBAI EXPRESS***INA68E***9301782***Wed***28-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***26***Mon***23-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***DUBAI EXPRESS***4218***9301782***Wed***28-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***27***Tue***24-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAMBURG SÜD***EM ATHENS***419E***9203538***Wed***28-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***39***Sun***06-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***SANTA RICARDA***04E22***9227314***Fri***30-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***46***Tue***15-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||MSC***MSC MICHAELA***NU421R***9230488***Sat***31-May-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***28***Sat***28-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***MAERSK BRATAN***422S***9394894***Mon***02-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***73***Thu***14-Aug-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||MAERSK LINE***MAERSK VIRGINIA***1407***9235531***Tue***03-Jun-2014***NEWARK, NEW JERSEY, UNITED STATES***USEWR***29***Thu***03-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAMBURG SÜD***HOUSTON EXPRESS***421E***9294991***Tue***03-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***31***Fri***04-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||CMA CGM***APL OMAN***INA70E***9400124***Wed***04-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***23***Fri***27-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||DELMAS***APL OMAN***INA70E***9400124***Wed***04-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***23***Fri***27-Jun-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***APL OMAN***4219***9400124***Wed***04-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***27***Tue***01-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***SEASPAN FELIXSTOWE***05E23***9227039***Fri***06-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***46***Tue***22-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||MSC***HS COLUMBIA***NU422R***9225079***Sat***07-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***28***Sat***05-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***SPIRIT OF MELBOURNE***423S***9362413***Mon***09-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***73***Thu***21-Aug-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||MAERSK LINE***MSC FIRENZE***1407***9252101***Tue***10-Jun-2014***NEWARK, NEW JERSEY, UNITED STATES***USEWR***29***Thu***10-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAMBURG SÜD***FRANKFURT EXPRESS***422E***9450442***Tue***10-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***31***Fri***11-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||CMA CGM***CMA CGM KINGFISH***INA72E***9330991***Wed***11-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***26***Mon***07-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||DELMAS***CMA CGM KINGFISH***INA72E***9330991***Wed***11-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***26***Mon***07-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***CMA CGM KINGFISH***4220***9330991***Wed***11-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***27***Tue***08-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***SEASPAN NINGBO***04E24***9227015***Fri***13-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***46***Tue***29-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||MSC***MSC DYMPHNA***NU423R***9110391***Sat***14-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***28***Sat***12-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAPAG-LLOYD***OLGA MAERSK***424S***9251614***Mon***16-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***73***Thu***28-Aug-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||MAERSK LINE***MAERSK KENTUCKY***1407***9193240***Tue***17-Jun-2014***NEWARK, NEW JERSEY, UNITED STATES***USEWR***29***Thu***17-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||HAMBURG SÜD***NAGOYA EXPRESS***423E***9450428***Tue***17-Jun-2014***NEW YORK, NEW YORK, UNITED STATES***USNYC***31***Fri***18-Jul-2014***EL ISKANDARIYA (= ALEXANDRIA), EGYPT***EGALY|||
只需在帖子请求中发送所有内容,您就会得到xls数据作为回报。将其写入文件,您就拥有了Excel文档。现在,我还没有完成将JSON转换为csv以满足您的需求,或者服务器的需求,但您应该能够将它完美地组合在一起。另一方面,POST和JSON部分,我确实进行了验证,所以希望能为您提供所需。
一方面注意 - 您无需登录即可使用。只需下载按钮本身就需要登录。有点相当于当你错过整个墙壁时锁上你的前门。