所以我不想拉整个页面,只是页面的前40KB。就像这个Facebook Debugger工具一样。如何通过cURL只抓取页面的第一个40KB
我的目标就是抓住社交媒体元数据,即og:image
等
可以在任何编程语言,PHP或者Python。
我确实有phpQuery代码,使用的file_get_contents /卷曲,我知道如何分析接收到的HTML,我的问题是“如何在没有获取整个页面抓取网页的只有第一NKB”
所以我不想拉整个页面,只是页面的前40KB。就像这个Facebook Debugger工具一样。如何通过cURL只抓取页面的第一个40KB
我的目标就是抓住社交媒体元数据,即og:image
等
可以在任何编程语言,PHP或者Python。
我确实有phpQuery代码,使用的file_get_contents /卷曲,我知道如何分析接收到的HTML,我的问题是“如何在没有获取整个页面抓取网页的只有第一NKB”
这可以用于:
curl -r 0-40000 -o 40k.raw https://www.keycdn.com/support/byte-range-requests/
个
的-r
代表范围:
来自卷边手册页:
r, --range <range>
(HTTP FTP SFTP FILE) Retrieve a byte range (i.e a partial document) from a HTTP/1.1, FTP or SFTP server or a local FILE. Ranges can be
specified in a number of ways.
0-499 specifies the first 500 bytes
500-999 specifies the second 500 bytes
-500 specifies the last 500 bytes
9500- specifies the bytes from offset 9500 and forward
0-0,-1 specifies the first and last byte only(*)(HTTP)
更多信息可以在本文中找到:https://www.keycdn.com/support/byte-range-requests/
以防万一,这是一个基本的例子如何与go
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
)
func main() {
response, err := http.Get("https://google.com")
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
data, err := ioutil.ReadAll(io.LimitReader(response.Body, 40000))
fmt.Printf("data = %s\n", data)
}
也许这将帮助https://stackoverflow.com/a/12014561/661872 –
@LawrenceCherone我在phpQuery中有使用file_get_contents/cURL的代码,并且我知道如何解析收到的HTML,我的问题是**“如何仅抓取页面的第一个nKB而不抓取整个页面”** – Umair
这似乎已经回答[这里](https://stackoverflow.com/questions/2032924/how-to-partially-download-a-remote-file-with-curl)。 – Dardanboy