Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getRecipeFromUrl($url){
- $html=getHtml($url);
- $dom = new DomDocument();
- $internalErrors = libxml_use_internal_errors(true);
- $dom->loadHTML($html);
- libxml_use_internal_errors($internalErrors);
- $finder = new DomXPath($dom);
- //recipe name
- $classname="recipe-panel-title";
- $nodes = $finder->query("//*[@class='" . $classname . "']");
- $recipe['name']= $nodes[0]->textContent;
- //recipe author
- $classname="btn btn-success btn-sm";
- $nodes = $finder->query("//*[@class='" . $classname . "']");
- $recipe['author']= trim(str_replace('©','', $nodes[0]->textContent));
- //recipe evaluation
- $classname="small";
- $nodes = $finder->query("//*[@class='" . $classname . "']");
- if($nodes[0])
- $recipe['score']= $nodes[0]->getAttribute('data-score');
- //recipe flavours
- $classname1="even";
- $classname2="odd";
- $nodes = $finder->query("//*[@class='$classname1' or @class='$classname2']");
- $recipe['flavours']=[];
- foreach ($nodes as $node){
- array_push($recipe['flavours'],
- $node->getElementsByTagName('a')[1]->textContent. ' '.
- '('. $node->getElementsByTagName('a')[0]->textContent.') '.
- $node->getElementsByTagName('div')[0]->textContent
- );
- }
- //stepping and vg
- $classname="table table-sm flavors";
- $nodes = $finder->query("//*[@class='" . $classname . "']")[0]->getElementsByTagName('tr');
- preg_match_all('!\d+(?:\.\d+)?!', $nodes[$nodes->length-2]->textContent, $matches);
- $recipe['stepping']=$matches[0][1];
- $recipe['vg']=$matches[0][2];
- $recipe['pg']=abs($recipe['vg']-100);
- return $recipe;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement