{"id":1081,"date":"2012-02-14T22:37:05","date_gmt":"2012-02-14T20:37:05","guid":{"rendered":"http:\/\/blog.sfsoft.it\/?p=1081"},"modified":"2012-02-14T22:37:05","modified_gmt":"2012-02-14T20:37:05","slug":"wget-e-reindirizzamenti-con-http-equiv-refreh-content","status":"publish","type":"post","link":"https:\/\/www.sfsoft.it\/blog\/2012\/02\/14\/wget-e-reindirizzamenti-con-http-equiv-refreh-content\/","title":{"rendered":"WGET e reindirizzamenti con http-equiv=refresh content"},"content":{"rendered":"<p>Pu\u00f2 capitare che serva schedulare un download periodico da un indirizzo che include un refresh intermedio di tipo <em>http-equiv=refresh content<\/em><\/p>\n<p>In questo caso <em>wget<\/em> sembra non riuscire ad intercettare il <em>redirect<\/em> e scarica solo il file <em>HTML<\/em> con contenuto le istruzioni per il <em>browser<\/em>.<\/p>\n<p>Per ovviare ho creato un piccolo <em>script<\/em> che usa in combinata <em>wget<\/em> e <em>grep<\/em>:<\/p>\n<pre lang=\"bash\">#!\/bin\/bash\r\nURL=\"http:\/\/www.miourl.com\/path\/\"\r\nREGEXP=\"http:\/\/[^[:space:]\\\"]*[zip$]\"\r\nFILE=\"\/path\/to\/download\/file.zip\"\r\nURL2=`wget -qO- $URL | grep -o -e $REGEXP`\r\nwget $URL2 -O $FILE<\/pre>\n<p>Questo piccolo <em>script<\/em> in pratica si occupa di prelevare il file <em>HTML<\/em> che contiene la direttiva di <em>refresh<\/em>, estrapolarne il <em>link<\/em> ( in questo caso da <em>http<\/em> a <em>zip<\/em> ma basta adattare la <em>regexp<\/em> alle proprie esigenze), memorizzarlo in un ulteriore variabile e eseguire <em>wget<\/em> con il link giusto, la parte <em>-O $FILE<\/em> \u00e8 facoltativa serve solo per salvare il file con un nome specifico invece che quello originale.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pu\u00f2 capitare che serva schedulare un download periodico da un indirizzo che include un refresh intermedio di tipo http-equiv=refresh content In questo caso wget sembra non riuscire ad intercettare il redirect e scarica solo il file HTML con contenuto le istruzioni per il browser. Per ovviare ho creato un piccolo script che usa in combinata [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[15,3],"tags":[52,16,8],"_links":{"self":[{"href":"https:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/posts\/1081"}],"collection":[{"href":"https:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/comments?post=1081"}],"version-history":[{"count":1,"href":"https:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/posts\/1081\/revisions"}],"predecessor-version":[{"id":1082,"href":"https:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/posts\/1081\/revisions\/1082"}],"wp:attachment":[{"href":"https:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/media?parent=1081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/categories?post=1081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/tags?post=1081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}