私はリモートURL上でcURLを使用している間、すべての画像をブロックしたいと思います。簡単な例を挙げておきます。ページには200個のjpgイメージがあり、200個のイメージがないページをcURLで取得したいと考えています。php cURLの使用中にURLの一部をブロックする方法はありますか?
0
A
答えて
7
URLをcURLすると、そのURLにあるものだけが受信されます。これは、おそらくHTMLドキュメントにすぎません。
cURLはではありません。は、HTMLドキュメントで参照されているすべての200個のイメージを自動的にダウンロードします。なぜなら、cURLはHTMLを気にしないからです。まったく逆。 にと200画像をすべてダウンロードするには、HTMLを手作業で解析し、個別の画像ごとにさらにcURLリクエストを行う必要があります。
$ curl -i www.w3.org
HTTP/1.1 200 OK
Date: Mon, 07 Feb 2011 02:46:36 GMT
Server: Apache/2
Content-Location: Home.html
Vary: negotiate,accept,Accept-Encoding
TCN: choice
Last-Modified: Tue, 01 Feb 2011 20:42:28 GMT
ETag: "74f2-49b3e92157500;89-3f26bd17a2f00"
Accept-Ranges: bytes
Content-Length: 29938
Cache-Control: max-age=600
Expires: Mon, 07 Feb 2011 02:56:36 GMT
P3P: policyref="http://www.w3.org/2001/05/P3P/p3p.xml"
Connection: close
Content-Type: text/html; charset=utf-8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- Generated from data/head-home.php, ../../smarty/{head.tpl} -->
<head>
<title>World Wide Web Consortium (W3C)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="Help" href="/Help/" />
<link rel="stylesheet" href="/2008/site/css/minimum" type="text/css" media="handheld, all" />
<style type="text/css" media="print, screen and (min-width: 481px)">
/*<![CDATA[*/
@import url("/2008/site/css/advanced");
/*]]>*/
</style>
<link href="/2008/site/css/minimum" rel="stylesheet" type="text/css" media="handheld, only screen and (max-device-width: 480px)" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="/2008/site/css/print" type="text/css" media="print" />
<link rel="shortcut icon" href="/2008/site/images/favicon.ico" type="image/x-icon" />
<meta name="description" content="The World Wide Web Consortium (W3C) is an international community where Member organizations, a full-time staff, and the public work together to develop Web standards." />
<link rel="alternate" type="application/atom+xml" title="W3C News" href="/News/atom.xml" />
</head>
<body id="www-w3-org" class="w3c_public w3c_home">
<div id="w3c_container">
<!-- Generated from data/mast-home.php, ../../smarty/{mast.tpl} -->
<div id="w3c_mast"><!-- #w3c_mast/Page top header -->
<h1 class="logo"><a tabindex="2" accesskey="1" href="/"><img src="/2008/site/images/logo-w3c-mobile-lg" width="90" height="53" alt="W3C" /></a> <span class="alt-logo">W3C</span></h1>
<div id="w3c_nav">
...
要求が取得するすべてのcURLです:コマンドラインから
例。そこに1つの画像:<img src="/2008/site/images/logo-w3c-mobile-lg" width="90" height="53" alt="W3C" />
があります。それはあなたが得ているすべてです。あなたはイメージ自体を手に入れていません。
0
イメージなしで取得することはできませんが、正規表現やDOMパーサーで結果を簡単に取り除くことはできますが、カールでは実際にイメージを要求していません。あなたはタグを取り除くだろうので、ページ上のhtml
私は200画像をダウンロードしたくない。私はそれらをブロックしたい。 –
@wildもう一度、cURL **はHTML文書で参照される画像をダウンロードしません。 cURLするにはすべてテキストだけで、テキストは*読み込まない*。したがって、イメージは自動的にダウンロードされないため、何もする必要はありません。 – deceze
あなたは実際にカール要求でイメージをダウンロードしていません。あなたはカール・リクエストの結果を出力しているので、カール・レスポンス・テキストからそれらを削除することを話していますか? –