Php crawls the data on this webpage. as long as the data is not html content, it then writes the json content into the file.

Source: Internet
Author: User
Php captures the data of this web page, as long as the data, do not html content, and then write the file after json, novice asking for http://www.okooo.com/Upload/sohu/table_23.html
I am asking for advice. the difficulty lies in regular expressions. I don't want to write regular expressions.


Reply to discussion (solution)

$url = 'http://www.okooo.com/Upload/sohu/table_23.html';$s = file_get_contents($url);preg_match_all('#
 < table>
  #isU', $s, $m);foreach(array_map('strip_tags', $m[0]) as $r) {  $a = preg_split('/\s+/', $r, -1, PREG_SPLIT_NO_EMPTY);  $res[] = array_chunk(array_slice($a, 0, -1), 3);}print_r($res);echo json_encode($res);
 <>
Array ([0] => Array ([0] => Array ([0] => ranking [1] => team [2] => points) [1] = & gt; Array ([0] = & gt; 1 [1] = & gt; Juventus [2] = & gt; 102) [2] => Array ([0] => 2 [1] => Rome [2] => 85) [3] => Array ([0] => 3 [1] => Naples [2] => 78) [4] => Array ([0] => 4 [1] => Florence [2] => 65) [5] => Array ([0] => 5 [1] => Milan [2] => 60) [6] => Array ([0] => 6 [1] => Parma [2] => 58) [7] => Array ([0] => 7 [1] => Turin [2] => 57) [8] => Array ([0] => 8 [1] => AC Milan [2] => 57) [9] => Array ([0] => 9 [1] => Azio [2] => 56) [10] => Array ([0] => 10 [1] => Verona [2] => 54 )) [1] => Array ([0] => Array ([0] => Number of players [1] => players [2] => Team) [1] => Array ([0] => 22 [1] => immobilai [2] => Turin) [2] => Array ([0] => 20 [1] => Tony [2] => Verona) [3] => Array ([0] => 19 [1] => Tevis [2] => Juventus) [4] => Array ([0] => 17 [1] => palcio [2] => Milan) [5] => Array ([0] => 17 [1] => iguain [2] => Naples) [6] => Array ([0] => 16 [1] => verente [2] => Juventus) [7] => Array ([0] => 16 [1] => DiNatale [2] => udínez) [8] => Array ([0] => 16 [1] => Jusepe Rosi [2] => Florence) [9] => Array ([0] => 16 [1] => Bellardi [2] => sasoro) [10] => Array ([0] => 15 [1] => cabin Hong [2] => Naples) [[["\ u6392 \ u540d ", "\ u7403 \ u961f", "\ u79ef \ u5206"], ["1", "\ u5c24 \ u6587 \ u56fe \ u65af", "102"], ["2", "\ u7f57 \ u9a6c", "85"], ["3", "\ u90a3 \ u4e0d \ u52d2 \ u65af", "78"], ["4", "\ u4f5b \ u7f57 \ u4f26 \ u8428", "65"], ["5", "\ u56fd \ u9645 \ u7c73 \ u5170 ", "60"], ["6", "\ u5e15 \ u5c14 \ u9a6c", "58"], ["7", "\ u90fd \ u7075 ", "57"], ["8", "AC \ u7c73 \ u5170", "57"], ["9", "\ u62c9 \ u9f50 \ u5965 ", "56"], ["10", "\ u7ef4 \ u7f57 \ u7eb3", "54"], [["\ u8fdb \ u7403 \ u6570 ", "\ u7403 \ u5458", "\ u7403 \ u961f"], ["22", "\ u4f0a \ u83ab \ u6bd4 \ u83b1", "\ u90fd \ u7075"], ["20", "\ u6258 \ u5c3c", "\ u7ef4 \ u7f57 \ u7eb3"], ["19", "\ u7279 \ u7ef4 \ u65af ", "\ u5c24 \ u6587 \ u56fe \ u65af"], ["17", "\ u5e15 \ u62c9 \ u897f \ u5965", "\ u56fd \ u9645 \ u7c73 \ u5170"], ["17", "\ u4f0a \ u74dc \ u56e0", "\ u90a3 \ u4e0d \ u52d2 \ u65af"], ["16", "\ u7565 \ u4f26 \ u7279 ", "\ u5c24 \ u6587 \ u56fe \ u65af"], ["16", "\ u8fea \ u7eb3 \ u5854 \ u83b1", "\ u4e4c \ u8fea \ u5185 \ u65af"] ["16", "\ u6731 \ u585e \ u4f69 \ u00b7 \ u7f57 \ u897f", "\ u4f5b \ u7f57 \ u4f26 \ u8428"], ["16 ", "\ u8d1d \ u62c9 \ u5c14 \ u8fea", "\ u838e \ u7d22 \ u7f57"], ["15", "\ u5361 \ u5217 \ u6d2a ", "\ u90a3 \ u4e0d \ u52d2 \ u65af"]
Write files, and you can practice it yourself.
Just a file_put_contents function

You don't have to use regular expressions either. try DOM processing and search for the Simple html dom.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.