dongsisui7562 2015-11-28 22:51
浏览 50
已采纳

解析Newegg网站的价格

I'm trying to get the price for the following product http://www.newegg.com/Product/Product.aspx?Item=N82E16822236715.

Using just jQuery, the following code is working and gives me the value before preprocessing

jQuery('.grpPrimary div[style = "display: block;"] .price-current').text()

I'm trying to do the same using Goutte and Laravel:

$client = new Client();
$crawler = $client->request('GET', 'http://www.newegg.com/Product/Product.aspx?Item=N82E16822236715');
$crawler = $crawler->filter('.grpPrimary div[style = "display: block;"] .price-current' )->each(function ($node) { 
ECHO  $node->text()."
";});

And I'm not getting the price value, I tried to select its parent divs but the price value is not being shown in any of them. It's the same with phpquery.

  • 写回答

1条回答 默认 最新

  • dseax40600 2015-11-28 23:07
    关注

    I don't tkink this is a good approach, just by exploring the returned HTML, I've seen that there is this small JS :

      var utag_data = {
      page_breadcrumb:'Home > Components > Hard Drives > Desktop External Hard Drives > Western Digital > Item#:9SIA29P2YK5768',
            page_tab_name:'Components',
            product_category_id:['15'],
            product_category_name:['Hard Drives'],
            product_subcategory_id:['414'],
            product_subcategory_name:['Desktop External Hard Drives'],
            product_id:['9SIA29P2YK5768'],
            product_web_id:['9SIA29P2YK5768'],
            product_title:['WD Elements 2TB USB 3.0 External Desktop Storage WDBWLG0020HBK-NESN Black'],
            product_manufacture:['Western Digital'],
            product_unit_price:['89.99'],
            product_sale_price:['79.99'],
            product_default_shipping_cost:['0.01'],
            product_type:['Seller'],
            product_model:['WDBWLG0020HBK-NESN'],
            product_instock:['1'],
            product_group_id:['30896206'],
            hl_seller_id_list:'A29P|A4P0|1|A6ZP|A2F8|A1N8|A24G|A0ZX|A8H5|A6AH',
            hl_prod_id_list:'9SIA29P2YK5768|9SIA4P02RJ6296|N82E16822236715|9SIA6ZP3K22742|9SIA2F83426160|9SIA1N81YB4387|9SIA24G2179173|9SIA0ZX1W07804|9SIA8H531C6923|9SIA6AH3AB2901',
            hl_prod_p_list:'79.99|89.99|94.99|106.62|109.35|110.29|109.59|113.93|131.86|131.69',
            hl_prod_qty_list:'1|1|1|1|1|1|1|1|1|1',
            parent_item:'N82E16822236715',
            page_type:'Product',
            site_region:'USA',
            site_currency:'USD',
            page_name:'ProductDetail',
            search_scope:jQuery('#haQuickSearchStore option:selected').text(),
            user_nvtc:Web.StateManager.Cookies.get(Web.StateManager.Cookies.Name.NVTC),
            user_name:Web.StateManager.Cookies.get(Web.StateManager.Cookies.Name.LOGIN,'LOGINID6'),
            third_party_render:['4774d6780334a7bf9c3c95255c60401916d07cae','78b8b16d9d0f6f2e8419ac12fa710f5153f1cee3','65531e14b4d9b9a223cc3bfcb65ce7b5f356011d','2a5e772a0f941c862180037f8a5c118c7abf2f7d','9011adc5233493f5adc5f0f0f1bcb655892c09e3']
    
      };
    

    So if I were you, I would do a Regex which will take every digits and points ([\d.]+) between product_sale_price:[' (product_sale_price:\[') and '] ('\])

    So it is something like this :

    product_sale_price:\['([\d.]+)'\]
    

    So in PHP it would be :

    $str = '...'; // The JS array OR the full HTML page will also work
    preg_match("/product_sale_price:\['([\d.]+)'\]/", $str, $matches);
    

    So your result would be stored inside the $matches array; so :

    $price = floatval($matches[1]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用