Docs Viewer

Upload, preview, download, and write quick documents without Word.

+ New Document

scrapeflash

scrapeflash.rtf

Calibri; ;; \*Riched20 10.0.22621 <?php set_time_limit(0); ini_set('display_errors', 1); error_reporting(E_ALL); // In run.php and other files where you use calculatePoints require_once 'calculate_points.php'; // Make sure the path to simple_html_dom.php is correct require_once 'simple_html_dom.php'; // Include Simple HTML DOM Parser // Update the allowed leagues with new leagues $allowedLeagues = [ "Premier League", "La Liga", "Bundesliga", "Copa de la Liga Profesional", "Primera Nacional", "Torneo Federal", "Primera B", "Primera C", "Copa Argentina", "Super Cup", "Ligue 1", "Algeria Cup", "A-League", "NPL ACT", "NPL Northern NSW", "NPL NSW", "NPL Queensland", "NPL South Australia", "NPL Tasmania", "NPL Victoria", "NPL Western Australia", "Australia Cup", "A-League Women", "2. Liga", "OFB Cup", "I Liqa", "Federation Cup", "Vysshaya Liga", "Pershaya Liga" ]; $baseUrl = "\*HYPERLINK https://www.flashscore.com https://www.flashscore.com"; $today = date("Y-m-d"); $outputFile = "data/match_data_\$today\.csv"; function fetchSportsMoleMetaInfo($url) \ $html = file_get_html($url); if (!$html) die("Failed to fetch the webpage from Sports Mole."); // Get the meta tags $metaData = []; // Match URL from twitter:url $metaData['url'] = $html->find('meta[property=twitter:url]', 0)->content ?? ''; // Match Title from twitter:title $metaData['title'] = $html->find('meta[property=twitter:title]', 0)->content ?? ''; // Match Description from twitter:description $metaData['description'] = $html->find('meta[property=twitter:description]', 0)->content ?? ''; // Match Image from twitter:image $metaData['image'] = $html->find('meta[property=twitter:image]', 0)->content ?? ''; // Optionally, you can scrape match details, like teams and predictions, from the page $teams = []; foreach ($html->find('.match-preview') as $match) \ $homeTeam = $match->find('.home-team', 0)->plaintext ?? 'Team A'; $awayTeam = $match->find('.away-team', 0)->plaintext ?? 'Team B'; $teams = [ 'home' => $homeTeam, 'away' => $awayTeam ]; \ // Combine all scraped data $matchDetails = array_merge($metaData, $teams); return $matchDetails; \ function fetchMatches($url, $allowedLeagues) \ $html = file_get_html($url); if (!$html) die("Failed to fetch the webpage."); $matches = []; foreach ($html->find(".event__match") as $match) \ $leagueElement = $match->parent()->parent()->find(".event__title--type", 0); if (!$leagueElement) continue; $leagueName = trim($leagueElement->plaintext); if (!in_array($leagueName, $allowedLeagues)) continue; $homeTeam = $match->find(".event__participant--home", 0)->plaintext ?? "Team A"; $awayTeam = $match->find(".event__participant--away", 0)->plaintext ?? "Team B"; $matchDetails = [ 'league' => $leagueName, 'home_team' => trim($homeTeam), 'away_team' => trim($awayTeam), 'date' => $today, 'time' => $match->find(".event__time", 0)->plaintext ?? "00:00", ]; // Fetch additional data $matchId = $match->getAttribute('id'); // Example match ID $detailsUrl = $baseUrl . "/match/\$matchId\/"; // Update with correct structure $matchDetails = array_merge($matchDetails, fetchMatchDetails($detailsUrl)); $matches[] = $matchDetails; \ return $matches; \ function fetchMatchDetails($url) \ $html = file_get_html($url); if (!$html) return []; $details = []; // Fetch standings $details['home_standing'] = $html->find(".home-standing", 0)->plaintext ?? "N/A"; $details['away_standing'] = $html->find(".away-standing", 0)->plaintext ?? "N/A"; // Fetch recent form $details['home_form'] = fetchRecentForm($html, "home"); $details['away_form'] = fetchRecentForm($html, "away"); // Fetch head-to-head stats $details['h2h'] = fetchHeadToHead($html); // Fetch injuries $details['injuries'] = fetchInjuries($html); return $details; \ function fetchRecentForm($html, $teamType) \ $form = []; $formElements = $html->find(".\$teamType\-form .form-result"); foreach ($formElements as $element) \ $form[] = $element->plaintext; \ return implode(",", $form); \ function fetchHeadToHead($html) \ $h2h = []; $h2hElements = $html->find(".h2h-matches .h2h-result"); foreach ($h2hElements as $element) \ $h2h[] = $element->plaintext; \ return implode(",", $h2h); \ function fetchInjuries($html) \ $injuries = []; $injuryElements = $html->find(".injury-list .player-name"); foreach ($injuryElements as $element) \ $injuries[] = $element->plaintext; \ return implode(",", $injuries); \ function saveMatchesToCSV($matches, $file) \ $fp = fopen($file, 'w'); if (!$fp) die("Failed to open file for writing."); fputcsv($fp, ["League", "Home Team", "Away Team", "Date", "Time", "Home Standing", "Away Standing", "Home Form", "Away Form", "H2H", "Injuries"]); foreach ($matches as $match) \ fputcsv($fp, $match); \ fclose($fp); echo "Scraped data saved to $file\"; \ // Add a form check to trigger the scraper manually if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['scrape_button'])) \ echo "Scraping matches for \$today\...\"; $matches = fetchMatches("\$baseUrl\/matches/", $allowedLeagues); if (empty($matches)) die("No matches found for today.\"); saveMatchesToCSV($matches, $outputFile); echo "Scraper finished successfully.\"; \ else \ echo "<form method='POST'> <button type='submit' name='scrape_button'>Scrape Matches</button> </form>"; \ ?>