Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何通过cURL仅获取页面的前40KB_Php_Python_Curl - Fatal编程技术网

Php 如何通过cURL仅获取页面的前40KB

Php 如何通过cURL仅获取页面的前40KB,php,python,curl,Php,Python,Curl,所以我不想拉整个页面,只拉页面的前40KB。就像这个工具一样 我的目标是抓取社交媒体元数据,例如,og:image等 可以是任何编程语言,PHP或Python 我在phpQuery中有使用file\u get\u contents/cURL的代码,我知道如何解析接收到的HTML,我的问题是“如何只获取页面的第一个nKB而不获取整个页面”这不是Facebook或任何其他社交媒体网站特有的,但使用python可以获取前40 KB,如下所示: import urllib2 start = urllib

所以我不想拉整个页面,只拉页面的前40KB。就像这个工具一样

我的目标是抓取社交媒体元数据,例如,
og:image

可以是任何编程语言,PHP或Python


我在phpQuery中有使用file\u get\u contents/cURL的代码,我知道如何解析接收到的HTML,我的问题是“如何只获取页面的第一个nKB而不获取整个页面”

这不是Facebook或任何其他社交媒体网站特有的,但使用python可以获取前40 KB,如下所示:

import urllib2
start = urllib2.urlopen(your_link).read(40000)

这并不是Facebook或任何其他社交媒体网站所特有的,但您可以使用python获得前40 KB,如下所示:

import urllib2
start = urllib2.urlopen(your_link).read(40000)
这可用于:

curl -r 0-40000 -o 40k.raw https://www.keycdn.com/support/byte-range-requests/
-r
代表范围:

从curl手册页:

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)
这可用于:

curl -r 0-40000 -o 40k.raw https://www.keycdn.com/support/byte-range-requests/
-r
代表范围:

从curl手册页:

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)

也许这将有助于@LawrenceCherone我在phpQuery中有使用file\u get\u contents/cURL的代码,我知道如何解析收到的HTML,我的问题是“如何只获取页面的第一个nKB而不获取整个页面”,这似乎已经得到了回答。
--range
cURL命令行选项似乎很适合,但是没有说太多的细节,公平地说,你可以考虑使用curl和
CURLOPT_WRITEFUNCTION
在读取40KB后中止,您也可以在点击
之前中止,这可能会对@lawrencerone有所帮助。我在phpQuery中有使用file\u get\u contents/cURL的代码,我知道如何解析收到的HTML,我的问题是“如何只获取页面的第一个nKB而不获取整个页面”这似乎已经得到了回答。
--range
curl命令行选项似乎很合适,但没有说明太多细节。公平地说,您可以考虑将curl与
CURLOPT\u WRITEFUNCTION一起使用,该函数在读取40KB后中止,您也可以在点击
后中止。这是否会在到达前40 KB时停止加载页面?@Umair它将只读取前40 KB。所以,是的,它会在那之后停止。这会在到达前40 KB时停止加载页面吗?@Umair它只会读取前40 KB。所以,是的,在那之后就停止了。