You can not select more than 25 topics 
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long. 
		
		
		
		
		
			
	
	
		
			
	
		
			This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
		 
	
		
		
			
				
				
					
						
						
						
							---
 
						
						
						
							layout: post
 
						
						
						
							title: 使用PHP批量下载Mediawiki站点的图片
 
						
						
						
							tags: [PHP, Mediawiki, 图片]
 
						
						
						
							---
 
						
						
						
							
 
						
						
						
							  又是万能的PHP!不过还是Mediawiki API的功劳<!--more-->    
 
						
						
						
							  最近我为了备份一下[某个Wiki站](http://zh.moegirl.org/)( ~~后来才知道原来转移到了[一个Wiki上](https://www.hmoegirl.com/),真的是好久没关注了~~  ) , ( )  
						
						
						
							  文本很好下载, , , ?  
						
						
						
							  
 
						
						
						
							# 解决方案
  
						
						
						
							? ? , , , !  
						
						
						
							  
 
						
						
						
							# Code
  
						
						
						
							```php
  
						
						
						
							<? php 
 
						
						
						
							set_time_limit ( 0 ); 
 
						
						
						
							ignore_user_abort (); 
 
						
						
						
							$list  =  array ( "图片数组" ); 
 
						
						
						
							
 
						
						
						
							    $arrlength = count ( $list ); 
 
						
						
						
							for ( $x = 0 ; $x < $arrlength ; $x ++ )  { 
 
						
						
						
							    $tmp  =  json_decode ( file_get_contents ( "https://MediaWiki的地址/api.php?action=parse&text=[[File:" . $list [ $x ] . "]]&contentmodel=wikitext&formatversion=2&format=json" ), true ); 
 
						
						
						
							    $preg = '/src="(.*?)"/is' ; 
 
						
						
						
							    preg_match ( $preg , $tmp [ parse ][ text ], $match ); 
 
						
						
						
							    $tt = $tt . "
  
						
						
						
							    " . $match [ 1 ]; 
 
						
						
						
							} 
 
						
						
						
							$markout  =  fopen ( "List.txt" ,  "w" )  or  die ( "Unable to open file!" ); 
 
						
						
						
							fwrite ( $markout ,  $tt ); 
 
						
						
						
							fclose ( $markout ); 
 
						
						
						
							die ( "Finish" ); 
 
						
						
						
							?> 
  
						
						
						
							``` 
 
						
						
						
							
 
						
						
						
							# P.S.
  
						
						
						
							, & list=allimages`这里获取。