lucksport web scraping work
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Hello

I have another scraping work , data should be extracted from
https://1x2.lucksport.com/default_en.shtml

For each match listed in home page the script should extract data and saved
in a data.txt file (one match per row), in this format

INT CF|16:50|Brabrand IF:Aarhus AGF|7.41|5.17|1.28|7.86|5.37|1.27

7.41|5.17|1.28 are opening odds
7.86|5.37|1.27 are closing odds

Thank you!

awarded to edwindrajaya

Crowdsource coding tasks.

1 Solution

Winning solution

<?php
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://1x2.7m.com.cn/data/index_en.js"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $raw = curl_exec($ch); 
    curl_close($ch);   

    $raw=substr($raw,strpos($raw,'[')+1);
    $arr=explode('",',$raw);
    $txt='';
    foreach ($arr as $row){
        $data=explode('|',$row);
        $raw_date = date_create_from_format('Y,m,j,H,i,0', $data[1]);
        $date1 =date_format($raw_date, 'H:i');
        $txt.= $data[3].'|'.$date1.'|'.$data[6].':'.$data[7].'|'.$data[8].'|'.$data[9].'|'.$data[10].$data[11].'|'.$data[12].'|'.$data[13]."\n";
        $txt.= $data[8].'|'.$data[9].'|'.$data[10]." are opening odds\n";
        $txt.= $data[11].'|'.$data[12].'|'.$data[13]." are closing odds\n";
    }
    file_put_contents('data.txt', $txt, LOCK_EX);
?>
Thank you but it does not work for me , I receive only errors "Notice: Undefined offset: 1 in D:\data2\tipster~averageodds.php on line 14 Warning: dateformat() expects parameter 1 to be DateTimeInterface, boolean given in D:\data2\tipster~averageodds.php on line 15 Notice: Undefined offset: 3 in D:\data2\tipster~averageodds.php on line 16 Notice: Undefined offset: 6 in D:\data2\tipster~averageodds.php on line 16 Notice: Undefined offset: 7 in D:\data2\tipster~averageodds.php on line 16 Notice: Undefined offset: 8 in D:\data2\tipster~averageodds.php on line 16 Notice: Undefined offset: 9 in D:\data2\tipster~averageodds.php on line 16 Notice: Undefined offset: 10 in D:\data2\tipster~averageodds.php on line 16 Notice: Undefined offset: 11 in D:\data2\tipster~averageodds.p
graz68 3 months ago
and nothing is saved on data.txt
graz68 3 months ago
It seems that the data was not successfully retrieved, do you run scripts from localhost from your desktop, or from a web server? and which php version you are using?
edwindrajaya 3 months ago
php 5.6.35 , I run from desktop
graz68 3 months ago
probably I do not have curl in php.ini let me check
graz68 3 months ago
ok it was curl, thank you
graz68 3 months ago
thank you
edwindrajaya 3 months ago