Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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
使用curl命令提取价格_Curl - Fatal编程技术网

使用curl命令提取价格

使用curl命令提取价格,curl,Curl,我尝试使用curl命令提取一些信息 通过一个简单的grep,我提取了标题: grep-o”[^php cli的DOMDocument+DOMXPath可以轻松提取价格 curl -ks https://bulevip.com/es/pre-entreno/20927-cellucor-c4-original-pre-workout-390-gr-60-servicios.html | php -r 'echo (new DOMXPath(@DOMDocument::loadHTML(stream

我尝试使用curl命令提取一些信息 通过一个简单的grep,我提取了标题:


grep-o”[^php cli的DOMDocument+DOMXPath可以轻松提取价格

curl -ks https://bulevip.com/es/pre-entreno/20927-cellucor-c4-original-pre-workout-390-gr-60-servicios.html | php -r 'echo (new DOMXPath(@DOMDocument::loadHTML(stream_get_contents(STDIN))))->query("//span[contains(@class,\"product-price-js\")]")->item(0)->getAttribute("content");'
顺便说一句

例如,您说您已经使用了标题提取

grep -o "<title>[^<]*" | sed -e 's/<[^>]*>//g'
将正确翻译任何html编码字符:)

如果我们对它进行测试:

$ echo '<title>bl&aring;b&aelig;rsyltet&oslash;y</title>' > html

$ cat html | grep -o "<title>[^<]*" | sed -e 's/<[^>]*>//g'
bl&aring;b&aelig;rsyltet&oslash;y

$ cat html | php -r 'echo (@DOMDocument::loadHTML(stream_get_contents(STDIN)))->getElementsByTagName("title")->item(0)->textContent;'
blåbærsyltetøy

$

您的标题提取器在任何HTML编码字符上都会失败。例如,如果标题是
blå;bæ;rsyltetø;y
,则正确的翻译是
blåbærsyltetøy
(挪威语代表
蓝莓酱
),但您的提取器将以完全不可读的
blå;bæ;rsyltetø;y
结尾。如果标题包含特殊字符,例如
&
^
,则提取器也将失败。要获得正确的翻译,您可以改为:
php-r'echo(@DOMDocument::loadHTML(stream_get_contents(STDIN))->getElementsByTagName(“title”)->item(0)->textContent;'
$ echo '<title>bl&aring;b&aelig;rsyltet&oslash;y</title>' > html

$ cat html | grep -o "<title>[^<]*" | sed -e 's/<[^>]*>//g'
bl&aring;b&aelig;rsyltet&oslash;y

$ cat html | php -r 'echo (@DOMDocument::loadHTML(stream_get_contents(STDIN)))->getElementsByTagName("title")->item(0)->textContent;'
blåbærsyltetøy

$
$ echo '<title>AT&amp;T</title>' > html

$ cat html | grep -o "<title>[^<]*" | sed -e 's/<[^>]*>//g'
AT&amp;T

$ cat html | php -r 'echo (@DOMDocument::loadHTML(stream_get_contents(STDIN)))->getElementsByTagName("title")->item(0)->textContent;'
AT&T