search
HomeBackend DevelopmentPHP TutorialPHP regular grabs images under the entire domain name

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
  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 if( is_array( $_tagArr[ $i ] ) ) {
  63. $this->roundTagA( $_tagArr[ $i ] );
  64. }
  65. else {
  66. if( stripos( $_tagArr[$i], self::$_CapSite['domain_name'] )
  67. === FALSE ) {
  68. continue;
  69. }
  70. if( in_array( $_tagArr[$i], self::$_overURL ) ) {
  71. continue;
  72. }
  73. self::$_overURL[] = $_tagArr[$i];
  74. if( count( self::$_overURL ) % self::$_CapSite['serialize_url_size'] == 0 ) {
  75. OperateFile::setText( self::$_Config['overURL'], serialize( self::$_overURL ) );
  76. }
  77. do {
  78. $_tagA = $this->getCapInstance( Http::get( $_tagArr[$i] ) );
  79. sleep( self::$_CapSite['preform_page_time'] * self::$_markTime );
  80. if( $this->_mark === TRUE ) {
  81. self::$_markTime = self::$_CapSite['preform_page_time'];
  82. break;
  83. }
  84. self::$_markTime *= 2;
  85. } while( true );
  86. /* parse the main page and return next page */
  87. $this->roundTagA( $_tagA );
  88. }
  89. }
  90. }
  91. public function parseQuestUrl() {
  92. self::import('http.Http');
  93. $_round_Arr = $this->getCapInstance( Http::get( self::$_CapSite['request_url'] ) );
  94. $this->roundTagA( $_round_Arr );
  95. }
  96. }
  97. ?>
复制代码


Statement
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software