Home Backend Development PHP Tutorial PHP regular grabs images under the entire domain name

PHP regular grabs images under the entire domain name

Jul 25, 2016 am 08:50 AM

Code source: jUnion

Applicable platforms: Windows, Linux (Ubuntu), php-5.2.5+, Apache

Function: Capture images of the entire site. There is no curl plug-in development with PHP yet. Later improvement

Configuration: Under the config directory
domain_name: domain name (default: bizhibar.com)
request_site: website URL (default: http://www.bizhibar.com/)
request_url: which page of the website to start from (default: http://www .bizhibar.com/)
accept_type: picture type (default: gif, bmp, png, ico, jpg, jpeg)
save_path: picture saving path (default: savefiles/)
partition_name: picture saving directory name prefix (default: img_ )
dir_file_limit: How many files each directory allows (default: 100)
serialize_img_size: How many image addresses are read before caching them into the accompImg file in the cache directory. These addresses will be ignored the next time you continue to crawl. (Default: 30)
serialize_url_size: Same as serialize_url_size, how many link addresses have been read before caching to the overURL under the cache directory
. These addresses will be ignored the next time you continue to crawl. (Default: 10)

Note: I welcome your criticism and advice. If you have any new questions or areas that need improvement, please give me feedback
  1. set_time_limit(0);
  2. require dirname(__FILE__).DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'Capture.const.php';
  3. require __Home__.'include'.__Os__.'Capture. class.php';
  4. $_cfg = array(
  5. 'site' => __Home__.'config'.__Os__.'capture.site.php',
  6. 'preg' => __Home__.'config'.__Os__. 'capture.preg.php',
  7. 'accompImg' => __Home__.'cache'.__Os__.'accompImg',
  8. 'overURL' => __Home__.'cache'.__Os__.'overURL'
  9. );
  10. $_parse = new Capture( $_cfg );
  11. $_parse->parseQuestUrl();
  12. ?>
Copy code
  1. /**
  2. * The main class
  3. * @author pankai<530911044@qq.com>
  4. * @date 2013-08-10
  5. */
  6. class Capture {
  7. private static $_Config = array();
  8. private static $_CapSite = NULL;
  9. private static $_CapPreg = NULL;
  10. private static $_overURL = array();
  11. private $_mark = FALSE;
  12. private static $_markTime = 1;
  13. /**
  14. * initialize the main class: Capture
  15. * @param $_cfg array
  16. */
  17. public function __construct( &$_cfg ) {
  18. self::$_Config = &$_cfg;
  19. self::$_CapSite = require $_cfg['site'];
  20. self::$_CapPreg = require $_cfg['preg'];
  21. foreach( self::$_CapPreg as $_key => $_value ) {
  22. self::$_CapPreg[$_key] = str_replace( '_request_site', self::$_CapSite['request_site'], $_value );
  23. }
  24. self::import( 'file.OperateFile' );
  25. if( file_exists( $_cfg['overURL'] ) && filesize( $_cfg['overURL'] ) > 0 ) {
  26. $_contents = OperateFile::readText( $_cfg['overURL'], filesize( $_cfg['overURL'] ) );
  27. self::$_overURL = unserialize( $_contents );
  28. }
  29. self::import('pivotal.Pivotal');
  30. if( file_exists( $_cfg['accompImg'] ) && filesize( $_cfg['accompImg'] ) > 0 ) {
  31. $_contents = OperateFile::readText( $_cfg['accompImg'], filesize( $_cfg['accompImg'] ) );
  32. Pivotal::$_accompImg = unserialize( $_contents );
  33. }
  34. }
  35. /**
  36. * load class, follow Java pragrammer(package): import com.jUnion.Capture
  37. * @param $_class
  38. */
  39. public static function import( $_class ) {
  40. require_once __Home__.'include'.__Os__.str_replace( '.', __Os__, $_class ).'.class.php';
  41. }
  42. /**
  43. * create an instance of Pivotal class
  44. * @param $_source
  45. */
  46. private function getCapInstance( &$_source ) {
  47. $this->_mark = FALSE;
  48. $_Captal = new Pivotal( self::$_Config, $_source );
  49. $_tagA = $_Captal->parseUrl();
  50. $this->_mark = TRUE;
  51. return $_tagA;
  52. }
  53. /**
  54. * go forward one by one
  55. * @param $_tagArr
  56. */
  57. private function roundTagA( &$_tagArr ) {
  58. if( $_tagArr == NULL ) {
  59. return;
  60. }
  61. $_tagArrLength = count( $_tagArr );
  62. for( $i = 0; $i < $_tagArrLength; $i ++ ) {
  63. if( is_array( $_tagArr[ $i ] ) ) {
  64. $this->roundTagA( $_tagArr[ $i ] );
  65. }
  66. else {
  67. if( stripos( $_tagArr[$i], self::$_CapSite['domain_name'] )
  68. === FALSE ) {
  69. continue;
  70. }
  71. if( in_array( $_tagArr[$i], self::$_overURL ) ) {
  72. continue;
  73. }
  74. self::$_overURL[] = $_tagArr[$i];
  75. if( count( self::$_overURL ) % self::$_CapSite['serialize_url_size'] == 0 ) {
  76. OperateFile::setText( self::$_Config['overURL'], serialize( self::$_overURL ) );
  77. }
  78. do {
  79. $_tagA = $this->getCapInstance( Http::get( $_tagArr[$i] ) );
  80. sleep( self::$_CapSite['preform_page_time'] * self::$_markTime );
  81. if( $this->_mark === TRUE ) {
  82. self::$_markTime = self::$_CapSite['preform_page_time'];
  83. break;
  84. }
  85. self::$_markTime *= 2;
  86. } while( true );
  87. /* parse the main page and return next page */
  88. $this->roundTagA( $_tagA );
  89. }
  90. }
  91. }
  92. public function parseQuestUrl() {
  93. self::import('http.Http');
  94. $_round_Arr = $this->getCapInstance( Http::get( self::$_CapSite['request_url'] ) );
  95. $this->roundTagA( $_round_Arr );
  96. }
  97. }
  98. ?>
复制代码


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

See all articles