Open silasary opened 5 years ago
I scrapped the legal sets from wotc website, so supposed to be okay
I’ll upload the code later
As long as wotc doesn't screw this page up, my scraper would get the set list correctly
`public static function getModernLegalSets() {
$url = 'https://magic.wizards.com/en/game-info/gameplay/formats/modern';
$options = [
'http'=> [
'method'=> 'GET',
'header'=> "Accept-language: en\r\n".
"User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n", // i.e. An iPad
],
];
$context = stream_context_create($options);
$htmlFull = @file_get_contents($url, false, $context);
$dropdown = [];
if($htmlFull!="")
{
$doc = new DOMDocument();
$internalErrors = libxml_use_internal_errors(true);
$doc->loadHTML($htmlFull);
libxml_use_internal_errors($internalErrors);
$xpath = new DOMXPath($doc);
foreach($xpath->query("//div[@id='gameinfo-formats-modern-2']") as $divContent)
{
if($ulList = $divContent->getElementsByTagName('ul')->item(1))
{
$sets = $ulList->getElementsByTagName('li');
foreach($sets as $set)
{
//Some set names has non-breaking space, need to be removed
$dropdown[] = str_replace( chr( 194 ) . chr( 160 ), '', $set->nodeValue);
}
}
}
}
return $dropdown;
}`
Should probably speak to mtgjson about an explicit "Modern Legal flag" or something?