Home index. php:
The code is as follows: |
Copy code |
<! DOCTYPE html> <Html> <Head> <Meta name = "author" content = "flute"/> <Meta http-equiv = "Content-Type" content = "text/html; charset = utf-8"/> <Title> webpage capture </title> <Link rel = "stylesheet" href = "main.css" media = "all"/> <Script type = "text/javascript" src = "jquery. js"> </script> <Script type = "text/javascript" src = "main. js"> </script> </Head> <Body> <H1> Web Grabber <Hr/> <Div class = "box"> <H2> Url <Div class = "form"> <Input type = "text" id = "project" value = "projectname"/> <Input type = "text" id = "url" value = "http: //" size = "60"/> <Button class = "submit" type = "button"> Get </button> <span id = "tip"> </span> </Div> www.111cn.net </Div> <Div class = "box"> <Span class = "all" id = "saveall"> Save All </span> <H2> List <Ul id = "list"> </Ul> </Div> </Body> </Html> |
Capture the page code grab. php:
The code is as follows: |
Copy code |
<? PHP /* * Flute * */ If (isset ($ _ POST ['URL']) { If (isset ($ _ POST ['project']) &! Is_dir ($ _ POST ['project']) mkdir ($ _ POST ['project'], 0777 ); Echo json_encode (grab ($ _ POST ['URL']); } Function grab ($ url ){ // $ Url = 'http: // ldixing-wordpress.stor.sinaapp.com/uploads/leaves/test.html '; $ Data = array (); $ File = preg_replace ('/^. * //', '', $ url ); If ($ content = file_get_contents ($ url ))! = False ){ If (isset ($ _ POST ['project']) file_put_contents ($ _ POST ['project']. '/'. $ file, $ content ); $ Pattern = '/<link .*? Href = ('| ")(.*?. Css) 1. *?> /I '; If (preg_match_all ($ pattern, $ content, $ matches )){ $ Data ['css '] = $ matches [2]; } $ Pattern = '/<script .*? Src = ('| ")(.*?. Js) 1. *?> /I '; If (preg_match_all ($ pattern, $ content, $ matches )){ $ Data ['js'] = $ matches [2]; } $ Pattern = '/ /I '; If (preg_match_all ($ pattern, $ content, $ matches )){ $ Data ['IMG '] = $ matches [2]; } $ Pattern = '/url (' | "| s )(.*?) 1)/I '; If (preg_match_all ($ pattern, $ content, $ matches )){ $ Data ['src'] = $ matches [2]; } } Return $ data; } Www.111cn.net Function vardump ($ obj ){ Echo '<pre> '; Print_r ($ obj ); Echo '</pre> '; } ?> |
Save. php:
The code is as follows: |
Copy code |
<? PHP /* * Flute * */ If (isset ($ _ POST ['URL']) & isset ($ _ POST ['project']) & isset ($ _ POST ['domain ']) { Extract ($ _ POST ); $ Url = preg_replace ('/?. * $/', '', $ Url ); $ File = $ url; $ Arr = explode ('/', $ file ); $ Length = sizeof ($ arr ); $ Filename = $ arr [$ length-1]; $ Root = $ project; $ Dir = $ root; If ($ domain = 'http '){ $ Dir = $ root. '/http '; If (! Is_dir ($ dir) mkdir ($ dir, 0777 ); } Else { $ File = $ domain. '/'. $ url; For ($ I = 0; $ I <$ length-1; $ I ++ ){ If (! Empty ($ arr [$ I]) { $ Dir. = '/'. $ arr [$ I]; If (! Is_dir ($ dir) mkdir ($ dir, 0777 ); } } } If (! File_exists ($ dir. '/'. $ filename) | filesize ($ dir. '/'. $ filename) = 0 ){ $ Content = file_get_contents ($ file ); File_put_contents ($ dir. '/'. $ filename, $ content ); } } ?> |
Usage:
1. Open the indexpage, enter the project name and the network to capture, and the network keyword is the end of the file name, such as index.html;
2. Click the Get button to obtain a list of all css, js, img, and other resources on the current page;
3. Click the css link to obtain the background resource image in the css file, which is appended to the back of the list;
4. Click Save All to Save All the files in the list and generate them according to the relative path;
5. If an http remote file exists on the webpage, it will be saved directly in the http folder;
6. Sometimes Get and Save will fail. It doesn't matter how many retries.