php scrapping and outputting a specific value or number in a given tag

前端 未结 2 1372
逝去的感伤
逝去的感伤 2021-01-28 14:31

so I\'m very new to php. But with some help, I\'ve figured out how to scrape a site if it has a tag identifier like h1 class=____

And even better, I\'ve figured out how

2条回答
  •  被撕碎了的回忆
    2021-01-28 14:52

    if you only care about that change percentage, try this and remove the whole foreach section:

    $query = "//tr[@id='id-ethereum']/td[contains(@class, 'percent-24h')]";
    $entries = $xpath->query($query);
    
    echo $entries->item(0)->getAttribute('data-usd'); //-5.15
    

    here are the rest of the columns:

    $xpath = new DOMXPath($doc);
    
    $market_cap = $xpath->query("//tr[@id='id-ethereum']/td[contains(@class, 'market-cap')]");
    echo $market_cap->item(0)->getAttribute('data-usd'); //30574084827.1
    
    
    $price = $xpath->query("//tr[@id='id-ethereum']/td/a[contains(@class, 'price')]");
    echo $price->item(0)->getAttribute('data-usd'); //329.567
    
    $circulating_supply = $xpath->query("//tr[@id='id-ethereum']/td/a[@data-supply]");
    echo $circulating_supply->item(0)->getAttribute('data-supply'); //92770467.9991
    
    
    $volume = $xpath->query("//tr[@id='id-ethereum']/td/a[contains(@class, 'volume')]");
    echo $volume->item(0)->getAttribute('data-usd'); //810454000.0
    
    
    $percent_change = $xpath->query("//tr[@id='id-ethereum']/td[contains(@class, 'percent-24h')]");
    echo $percent_change->item(0)->getAttribute('data-usd'); //-3.79
    

提交回复
热议问题