小编Jit*_*een的帖子

Php cURL Web Scraping

我想从网站上抓取手机的价格网址:http://www.flipkart.com/apple-iphone-5s/p/itmdv6f75dyxhmt4? pid = MOBDPPZZDX8WSPAT

如果您查看代码,价格将放在以下SPAN中

<div class="pricing line">
        <div class="prices" itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">
                    <div>
                        <span class="selling-price omniture-field" data-omnifield="eVar48" data-eVar48="37500">Rs. 37,500</span> // Fetch this price
                    </div>
                    <span class="sticky-message">Selling Price</span>
            <meta itemprop="price" content="37,500"> 
            <meta itemprop="priceCurrency" content="INR">
        </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我到目前为止获取此代码的代码是:

<?php
$curl = curl_init('http://www.flipkart.com/apple-iphone-5s/p/itmdv6f75dyxhmt4?pid=MOBDPPZZDX8WSPAT');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

$page = curl_exec($curl);

if(!empty($curl)){ //if any html is actually returned

    $pokemon_doc->loadHTML($curl);
    libxml_clear_errors(); //remove errors for yucky html

    $pokemon_xpath = new DOMXPath($pokemon_doc);

    //get all the h2's with an id
    $pokemon_row = $pokemon_xpath->query('//h2[@id]');

    if($pokemon_row->length > …
Run Code Online (Sandbox Code Playgroud)

html php xpath domdocument web-scraping

4
推荐指数
1
解决办法
1万
查看次数

在PHP中使用header卷曲请求

我想向URL发出cURL请求以及以下标头:

“内容类型:application / json”,“授权”:“基本XXXXXXXXXX”

我有以下代码:

<?php

$post_url = "https://api.interlinkexpress.com/user/?action=login";

$curl = curl_init($post_url);

$headers = array(
        'Content-Type: application/json',
        'Authorization': 'Basic XXXXXXXXX'
        );
//curl_setopt($curl, CURLOPT_USERPWD, "username":"Password");
curl_setopt($curl, CURLOPT_URL, $post_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, true);
//curl_setopt($curl, CURLOPT_POSTFIELDS,json_encode($post_data) );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
$post_response = curl_exec($curl); 

?>
Run Code Online (Sandbox Code Playgroud)

结果显示为:

客户发送了错误的请求

这是$ header数组下的'Authorization ...'行

任何建议/帮助表示赞赏。

php post curl

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

php ×2

curl ×1

domdocument ×1

html ×1

post ×1

web-scraping ×1

xpath ×1