• Ok so I got some coding done to pull data from a leafly menu,
    But now I need to style it.

    So heres the data I need pulled,
    Leafly Menu

    This is the code:

    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <?php
    $category = isset($_REQUEST["cat"]) ? $_REQUEST["cat"] : "Flowers";
    $html = file_get_contents("https://www.leafly.com/dispensary-info/new-vansterdam/menu");
    $doc = new DOMDocument();
    $doc->strictErrorChecking = false;
    $doc->recover=true;
    @$doc->loadHTML("<html><body>".$html."</body></html>");
    
    $xpath = new DOMXpath($doc);
    $elements = $xpath->query("//*/div[@class='m-accordion--main-group']");
    if (!is_null($elements)) {
       foreach ($elements as $element) {
          $i = 0;
          $nodes = $element->childNodes;
          foreach ($nodes as $node) {
    		 $data = trim(strip_tags($node->nodeValue));
    		 if($i == 1 && $data != $category)
    		 {
    			continue 2;
    		 }
    		 echo $node->nodeValue."<br/>";
    		 $i++;
         }
       }
    }
    ?>
    <?php
    /*$doc = new DOMDocument;
    
    // We don't want to bother with white spaces
    $doc->preserveWhiteSpace = false;
    
    // Most HTML Developers are chimps and produce invalid markup...
    $doc->strictErrorChecking = false;
    $doc->recover = true;
    
    $doc->loadHTMLFile('https://www.leafly.com/dispensary-info/new-vansterdam/menu');
    
    $xpath = new DOMXPath($doc);
    
    $query = "//div[@class='m-accordion--main-group']";
    
    $entries = $xpath->query($query);
    echo htmlspecialchars($entries->item(0)->textContent);exit;*/
    
    ?>

    And it puts it on this page:
    Menu Page

    But I need to get it to look like the leafly page styling,
    or custom style it myself but idk how to call the classes for the product name, rating, and price.

    On the leafly page, the class title of the item is:
    <h3 class="copy--sm copy-sm--lg padding-rowItem l-ellipsis">Bettie Page</h3>

  • The topic ‘Styling scraped data from external site.’ is closed to new replies.