顯示具有 wget 標籤的文章。 顯示所有文章
顯示具有 wget 標籤的文章。 顯示所有文章

2018年4月20日 星期五

[SEO] Google search console 與使用 wget 建立 sitemap @ macOS 10.13.14

最近公司換了網域,導流量過程中需要安置個 sitemap 來增加曝光,就先查了一下 Google 牌的定義:

https://support.google.com/webmasters/answer/183668?hl=zh-Hant

不錯不錯,可以提交純文字,那就搭配個 wget 吧!

$ time wget --spider --recursive --no-verbose --output-file=log.txt https://example.com/
...
real 87m25.965s
user 0m1.836s
sys 0m4.081s


真久,接著再靠 grep 跟 awk 即可:

$ grep -op "URL:http[s]://\(.*\) " ~/log.txt | awk '{print(substr($1,5));}' > sitemap.txt

搞定!

2014年11月25日 星期二

[PHP] 使用 CodeIgniter 和 codeigniter-restserver 建立 RESTful API 以及測試方式 @ Ubuntu 14.04

環境資訊:

  • Ubuntu 14.04 64 Bit (lsb_release -a)
  • PHP 5.5.9 (php -v)
  • CodeIgniter 2.2.0 (echo CI_VERSION)

接著,透過 github.com/chriskacerguis/codeigniter-restserver 擴充 CodeIgniter:

$ wget https://raw.githubusercontent.com/chriskacerguis/codeigniter-restserver/master/application/config/rest.php -O /path/ci_proj/application/config/rest.php

$ wget https://raw.githubusercontent.com/chriskacerguis/codeigniter-restserver/master/application/libraries/Format.php -O /path/ci_proj/application/libraries/Format.php

$ wget https://raw.githubusercontent.com/chriskacerguis/codeigniter-restserver/master/application/libraries/REST_Controller.php -O /path/ci_proj/application/libraries/REST_Controller.php


接著,請確認 application/config/rest.php 設定:

$config[rest_default_format] = 'json'; // 預設為 xml

之後,就可以撰寫簡單的 RESTful API 啦:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require(APPPATH.'/libraries/REST_Controller.php');

class Item extends REST_Controller {
        public function index_get() {
                $this->list_get();
        }
        public function index_post() {
                $this->add_post();
        }
        public function index_put() {
                $this->update_put();
        }
        public function index_delete() {
                $this->delete_delte();
        }

        public function list_get() {
                echo "list";
        }
        public function add_post() {
                echo "create";
        }
        public function update_put() {
                echo "put";
        }
        public function remove_delete() {
                echo "remove";
        }
}


測試方式:

取得清單(GET)

$ curl -X GET http://localhost/ci_proj/item/list
$ curl -X GET http://localhost/ci_proj/item/

新增資料(POST)

$ curl -X POST http://localhost/ci_proj/item/add
$ curl -X POST http://localhost/ci_proj/item/


更新資料(PUT)

$ curl -X PUT http://localhost/ci_proj/item/update
$ curl -X PUT http://localhost/ci_proj/item/


刪除資料(DELETE)

$ curl -X DELETE http://localhost/ci_proj/item/delete
$ curl -X DELETE http://localhost/ci_proj/item/


也可以用 wget --method GET/POST/PUT/DELETE 等進行測試。

至於 RESTful 常見的 HTTP STATUS CODE,可以參考 Using HTTP Methods for RESTful Services

例如:

取得清單成功回應 200 OK,失敗則為 404 NOT FOUND;新增資料成功 200 OK 或是 201 LOCATION 到新增項目的 URI,失敗為 404 NOT FOUND;更新資料成功為 200 OK,失敗為 404 NOT FOUND;刪除資料成功為 200 OK,失敗為 404 NOT FOUND。

接著,是設計每個 GET, POST, PUT, DELETE API 細節,可以分別使用 $this->get('param')、$this->post('param')、$this->put('param') 和 $this->delete('param') 取得對應資料,而回應時,需要的 HTTP Status Code 可以使用:

$this->response( array('status' => true), 200);
$this->response( array('status' => false, 'error' => 'error message'), 400);
$this->response( array('status' => false, 'error' => 'error message'), 404);


若要 debug 的話,大概可以用:

$this->response( array('status' => true, 'get' => $this->get(), 'post' => $this->post(), 'put' => $this->put(), 'delete' => $this->delete() ), 200);

搭配 curl -i -X GET|POST|PUT|DELETE -d 'key=value' 方式進行,除了可以看到 HTTP Response code 外,也能看到 get, post, put, delete 各種參數資訊:

$ curl -i -X DELETE -d "haha=hehe" CGI
HTTP/1.1 200 OK
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.5
Content-Length: 68
Content-Type: application/json; charset=utf-8

{"status":true,"get":[],"post":[],"put":[],"delete":{"haha":"hehe"}}

2014年7月3日 星期四

[Linux] 使用 wget 測試 Remote Resource Availability @ Ubuntu 14.04

wget 有 --spider 模式,挺方便的 :P

$ wget --spider http://www.google.com/favicon.ico
Spider mode enabled. Check if remote file exists.
Resolving www.google.com (www.google.com)... 173.194.33.148, 173.194.33.144, 173.194.33.145, ...
Connecting to www.google.com (www.google.com)|173.194.33.148|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [image/x-icon]
Remote file exists.

2014年5月23日 星期五

使用 Wget 進行簡易的 Web Crawling

$ wget --recursive --no-clobber --html-extension --convert-links --no-parent --wait 5 --domains example.com www.example.com

如此一來,會在當前目錄建立 www.example.com 目錄,將依照網站目錄結構存儲起來。

2014年5月22日 星期四

使用 Wget 抽取 Web Page 所有的 Links (關鍵字 href="")

簡易用 Wget 達成:

$ wget -q --no-check-certificate -O - https://tw.yahoo.com | grep -o 'href=['"'"'"][^"'"'"'#]*['"'"'"]' | sed -e 's/^href=["'"'"']//' -e 's/["'"'"']$//' | grep -v "javascript:" | uniq 註:wget 有 --convert-links 可用

2014年1月26日 星期日

[OSX] 使用 ffmpeg 將 mp4 list 依序串接起來 (ffmpeg concat) @ Mac OS X 10.9

最近研究了一下對岸的影音播放,發現有的服務實作時,將一部短片以固定時間進行切割,這樣在服務眾人或是走 P2P 時,可以很方便進行分流,然而,若要把它弄成一個檔案,那就得花點功夫了,好家在用 ffmpeg 就可以搞定囉:How to concatenate (join, merge) media files

以 mp4 為例:

$ ffmpeg -i file1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts '/tmp/tmp1'
$ ffmpeg -i file2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts '/tmp/tmp2'
$ ffmpeg -i "concat:/tmp/tmp1|/tmp/tmp2" -c copy -bsf:a aac_adtstoasc output.mp4


接著,嫌太慢就寫個 script 來處理 XDD

$ python ffmpeg-concat-mp4-files.py --files file1.mp4 file2.mp4 --output out.mp4
$ python ffmpeg-concat-mp4-files.py --m3u /tmp/m3u.list --output out.mp4


其中 m3u 是支援 http 的描述,也就是會把網路上的東西用 wget 下載回 tmp 區。因此 ffmpeg-concat-mp4-files.py 需要有 ffmpeg 跟 wget 指令才能。