duanjiong2021 2018-04-08 20:12
浏览 92

我无法访问具有父类名称的span

I try this code But It's Return NULL object!

<?php
ini_set('max_execution_time', 300);
include_once ('Scraper.php');
$scraper = new Scraper();
$pageUrl = 'https://www.zara.com/tr/en/wrap-blouse-with-bow-p04437059.html?v1=6022035&v2=943001';
$pageHtmlContent = $scraper->curl($pageUrl);
$dom=new DOMDocument();
$dom->load($pageHtmlContent);
$xpath=new DOMXPath($dom);
$prise= $xpath->evaluate('(//div[@class=\'._product-price\'])');
var_dump($prise);
?>

I use selectorGadget to Make XPATH Address .

  • 写回答

1条回答 默认 最新

  • duanmo6937 2018-04-09 07:53
    关注

    Sorry, can't add comment, not enaugh reputation :(.

    You'r xpath is incorect, I can't find anything in given url. Please provide what you wish to find.

    Edit to comment

    To find exact div (as I tried, there is only 1 div with certains class in given url), use this xpath (//*[contains(@class,'_product-price')]). If you need the price that is within that div, use this xpath (//*[contains(@class,'_product-price')]/span). If there will be more then 1 xpath, use this (//*[contains(@class,'_product-price')]/span)[i] where i is within loop over DOM elements.

    e.g.

    dom_elements = [get_dom_elements]
    store_value = []
    i = 1
    while i < len(dom_elements):
        xpath = '(//*[contains(@class,'_product-price')]/span)[i]'
        store_value.append(some_function_for_getting_value_of_dom(xpath))
        i += 1
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀