A PHP spider crawler made with curl, regular expressions

Source: Internet
Author: User
Phoenix Network FCMS Content Management system
Get.php crawl frame, analysis and processing of web content and related substitution
Std.php Universal Regular
news_67_com.php to Http://news.67.com's crawl analyzer
Catch the list first, then grab the content page.
Also lack of monitoring, statistics, error handling functions. Personally think it is more fun.
  1. Include_once dirname (__file__). '/std.php ';
  2. $site = Array (
  3. ' Aname ' = ' China Entertainment Network ',
  4. ' Domain ' = ' news.67.com ',
  5. ' dirname ' \ = ' directory name, used to match the text based on different directories ',
  6. ' GetType ' = ' default ',
  7. Get Master File
  8. ' Creg ' = '/(SI) (. *?) \<\!--article end-->/',
  9. ' Code ' = ' Utf-8 ',
  10. ' Sub ' = ' Get subdirectory regular ',
  11. ' Content ' = ' tag1 ',
  12. ' img_upload ' = = Array (' tag1 ' = ') ',
  13. Next page
  14. ' Reg_next '/' = '/(? is) next page \>\><\/a>/',
  15. ' Key0 ' = '/' (? is)/',
  16. ' Key0_ap ' = = Array (array (', ', ' | '), "),
  17. ' tag0 ' = '/(? is)

    ([^<^>]*?) <\/h1>/',

  18. ' Tag0_arp ' = Array (
  19. Array
  20. '/(? is) \ (Photos \)/',
  21. '/(? is) \ (Figure \)/',
  22. '/(? is) \ (Figure \.\./',
  23. '/(? is) \ (Photos \.\./',
  24. '/(? is) \./',
  25. '/(? is) ("|")/',
  26. ),
  27. Array
  28. '', '', '', '', '', '',
  29. )
  30. ),
  31. ' Tag1 ' = '/(? is) (. *?) /',
  32. ' TAG1_BRP ' = Array (
  33. Array
  34. '/(? is) (. *?)/',
  35. '/(? is) \ (. *?\)/',
  36. '/(? is) \s*

    .*? (.*?) <\/p>\s*/',

  37. '/(? is) \s*

    \s*/',

  38. '/(? is) \s*

    \s*/',

  39. '/(? is)/',
  40. '/(? is)
    /',
  41. '/(? is) \s*

    \s*/',

  42. '/(? is) \s*

    \s*/',

  43. '/(? is) \s* \s*/',
  44. '/(? is) \s*<\/center>\s*/',
  45. '/(? is) \s*

    \s*/',

  46. ),
  47. Array
  48. '', '', '

    ', '

    ', '

    ', '', '', '

    ', '

    ', '

    ', '

    ', '

    '

  49. ),
  50. ),
  51. ' Tag1_arp ' = Array (
  52. Array
  53. '/(? is)

    <\/p>/',

  54. '/(? is)<\/strong>/'
  55. ),
  56. Array
  57. '', ''
  58. ),
  59. ),
  60. ' Strip ' = = Array (' tag1 ' = ') ',
  61. ' Tag2 ' + '/(? is) Guide: \s* (. *?) \s*<\/div>/',
  62. ' Tag2_arp ' = Array (
  63. Array
  64. '/(? is)/'
  65. ),
  66. Array
  67. ''
  68. ),
  69. ),
  70. ' Tag3 ' + '/(? is) (China Entertainment Network)/',
  71. ' Tag4 ' = '/(? is) Date: (\d+-\d+-\d+ \d+:\d+:\d+). *?<\/div>/',
  72. );
  73. $map = Array (
  74. ' Tag ' = ' key0 ',
  75. ' Title ' = ' tag0 ',
  76. ' Content ' = ' tag1 ',
  77. ' Summary ' = ' Tag2 ',
  78. ' Source ' = ' tag3 ',
  79. ' Pub_date ' = ' tag4 ',
  80. );
  81. $site _list = Array (
  82. ' Aname ' = ' China Entertainment Network ',
  83. ' Domain ' = ' www.67.com ',
  84. ' GetType ' = ' default ',
  85. ' Creg ' = '/(SI) (. *?) /',
  86. ' Code ' = ' GBK ',
  87. ' Reg_next ' = '/' (? si)
  88. Next page <\/a><\/li>/',
  89. Link
  90. ' tag0 ' = '/(? is). *? [^<^>]*?<\/a>.*?<\/div>/',
  91. Title
  92. ' Tag1 ' = '/(? is). *? ([^<^>]*?) <\/a>.*?<\/div>/',
  93. ' Tag1_arp ' = Array (
  94. Array
  95. '/(? is) \ (Photos \)/',
  96. '/(? is) \ (Figure \)/',
  97. '/(? is) \ (Figure \.\./',
  98. '/(? is) \ (Photos \.\./',
  99. '/(? is) \./',
  100. '/(? is) ("|")/',
  101. ),
  102. Array
  103. '', '', '', '', '', '',
  104. )
  105. ),
  106. );
  107. $list _map = Array (
  108. ' url ' = ' tag0 ',
  109. ' Title ' = ' Tag1 ',
  110. );
  111. $site _list_sub = Array ();
Copy Code
    1. Global $STD;
    2. $STD = Array (
    3. ' url ' = ' [0-9a-za-z\.\:\-\/%_#;&]+ ',
    4. ' img ' = '/' (? is)/',
    5. );
Copy Code
  1. /**
  2. * test.php
  3. *
  4. * @author xzfred
  5. * @copyright fengone.com
  6. * @created 2010-12-07.
  7. * @version $Id: php.php 3 2008-10-10 07:49:21z Fred $
  8. * Svnpath $HeadURL: http://192.168.0.16/svn/vim/skeletons/php.php $
  9. */
  10. /*
  11. Include_once "std.php";
  12. Include_once "lady_163_com.php";
  13. */
  14. Include_once $GLOBALS [' G_dir_core ']. "Get.php";
  15. //================================================================================
  16. Include_once Dir_host_tag. '/tuku_ent_china_com.php ';
  17. $obj = new Fchtmlparse ($site);
  18. $c = $obj->parse (file_get_contents ("Http://tuku.ent.china.com/fun/html/2011-08-23/181703.xml"));
  19. echo "\n\n\n ===================\n";
  20. echo $c [' field '] [' tag1 '][0];
  21. echo "\n\n\n ===================\n";
  22. Var_dump ($c);
  23. Exit ();
  24. List test
  25. $obj = new Fchtmlparse ($site _list);
  26. $c = $obj->parse (file_get_contents ("http://tuku.ent.china.com/fun/html/3569_1.html"));
  27. Var_dump ($c);
  28. Exit ();
  29. /*
  30. $obj = new Fchtmlget ($site);
  31. $c = $obj->getpage (' http://star.pclady.com.cn/entertainment/ss/1106/703240.html ');
  32. Var_dump ($c);
  33. $obj = new Fchtmlget ($site);
  34. $c = $obj->getpage (' http://star.pclady.com.cn/entertainment/ss/1106/703240.html ');
  35. Var_dump ($c);
  36. $obj = new Fchtmlparse ($site);
  37. $img _obj = new Fchtmlimgupload ($site);
  38. $data = file_get_contents ("e:/b.html");
  39. $c = $obj->parse ($data);
  40. $ic = $img _obj->upload ($c [' tag '] [' Tag1 '][0]);
  41. Var_dump ($ic);
  42. $data = file_get_contents ("e:/a.html");
  43. $c = $obj->parse ($data);
  44. $ic = $img _obj->upload ($c [' tag '] [' Tag1 '][0]);
  45. Var_dump ($ic);
  46. */
  47. Var_dump ($c [' tag '] [' tag1 ']);
Copy Code
  1. Include_once $GLOBALS [' G_dir_core ']. ' host/std.php ';
  2. $site = Array (
  3. ' Aname ' and ' China Network Entertainment Gallery ',
  4. ' Domain ' = ' tuku.ent.china.com ',
  5. ' dirname ' \ = ' directory name, used to match the text based on different directories ',
  6. ' GetType ' = ' default ',
  7. Get Master File
  8. ' Creg ' = '/(SI) ( .*?<\/list>)/',
  9. ' Code ' = ' Utf-8 ',
  10. ' Sub ' = ' Get subdirectory regular ',
  11. ' Content ' = ' tag1 ',
  12. ' img_upload ' = = Array (' tag1 ' = ') ',
  13. Next page
  14. ' Reg_next '/' = '/(? is) next page <\/a>/',
  15. ' Key0 ' = '/' (? is)/',
  16. ' Key0_ap ' = = Array (array (', ', ' | '), "),
  17. ' tag0 ' = '/(? is) title= "([^"]*?) " /',
  18. ' Tag0_arp ' = Array (
  19. Array
  20. '/(? is) \ (Figure \)/',
  21. '/(? is) \ "/',
  22. '/(? is) Exclusive:/',
  23. '/(? is) Exclusive:/',
  24. '/(? is) ("|")/',
  25. ),
  26. Array
  27. '', '', '', '', '',
  28. )
  29. ),
  30. ' Tag1 ' = '/(? is) (. *?) <\/list>/',
  31. ' TAG1_BRP ' = Array (
  32. Array
  33. '/(? is) \s*\s*/'
  34. ),
  35. Array
  36. '

  37. $

  38. $

    '
  39. )
  40. ),
  41. ' Tag1_arp ' = Array (
  42. Array
  43. '/(? is)

    ([^<^>]*?) <\/p>/',

  44. '/(? is) \<br\/\>/',
  45. ),
  46. Array
  47. '

    $

    ',
  48. '',
  49. )
  50. ),
  51. ' Strip ' = = Array (' tag1 ' = ') ',
  52. Network Name
  53. ' Tag3 ' = '/(? is)([^<^>]*?) <\/span>/',
  54. ' Tag4 ' + '/(? is) (China net)/'
  55. );
  56. $map = Array (
  57. ' Tag ' = ' key0 ',
  58. ' Title ' = ' tag0 ',
  59. ' Content ' = ' tag1 ',
  60. ' Author ' = ' Tag3 ',
  61. ' Source ' = ' tag4 '
  62. );
  63. $site _list = Array (
  64. ' Aname ' and ' China Network Entertainment Gallery ',
  65. ' Domain ' = ' tuku.ent.china.com ',
  66. ' GetType ' = ' default ',
  67. ' Creg ' = '/(SI) (. *?) <\/div>/',
  68. ' Code ' = ' Utf-8 ',
  69. ' Reg_next ' = '/' (? si)
  70. Next page <\/a><\/li>/',
  71. Link
  72. ' tag0 ' = '/(? is). *?<\/span>[^<^>]*?<\/a><\/div>/',
  73. ' TAG0_BRP ' = Array (
  74. Array
  75. '/(? is) \.htm/',
  76. ),
  77. Array
  78. '. Xml '
  79. )
  80. ),
  81. Title
  82. ' Tag1 ' = '/(? is).*?<\/span> ([^<^>]*?) <\/a><\/div>/',
  83. ' Tag1_arp ' = Array (
  84. Array
  85. '/(? is) \ (Figure \)/',
  86. '/(? is) \ "/',
  87. '/(? is) Exclusive:/',
  88. '/(? is) Exclusive:/',
  89. '/(? is) ("|")/',
  90. ),
  91. Array
  92. '', '', '', '', '',
  93. )
  94. ),
  95. );
  96. $list _map = Array (
  97. ' url ' = ' tag0 ',
  98. ' Title ' = ' Tag1 ',
  99. );
  100. $site _list_sub = Array ();
Copy Code
  • 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.