Home > Backend Development > PHP Tutorial > PHP+jQuery+POST collection web page example

PHP+jQuery+POST collection web page example

WBOY
Release: 2016-07-25 08:47:34
Original
1050 people have browsed it
Use JQuery's powerful DOM manipulation capabilities to collect page data,
then organize the data and send it to itself in the form of POST,
itself receives the data from POST and then writes it to the file in CSV format.

Disclaimer:
This program is only for use For learning and demonstration purposes, please do not frequently collect the URLs in the examples;
so as not to cause unnecessary trouble to the target website!
Everyone is welcome to provide comments
  1. set_time_limit(0);
  2. $num = range(0, 49100, 100);
  3. $base = 'http://www.zjchina.org/mspMajorIndexAction.fo?&startcount=';
  4. $page = isset($_GET['startcount']) ? $_GET['startcount'] : 0;
  5. $next_url = $_SERVER['SCRIPT_NAME'].'?startcount='.($page+1);
  6. if ( !isset($num[$page]) ) { exit('Collection completed'); }
  7. //Submit data
  8. if ( $_POST && count($_POST) && isset($_POST['send' ]) ) {
  9. $send = $_POST['send'];
  10. $file = dirname(__FILE__).'/data.csv';
  11. if ( file_exists($file) ) { unset($send[0]) ; }
  12. $fp = fopen($file, 'a+');
  13. foreach($send as $line) { fputcsv($fp, $line); }
  14. fclose($fp);
  15. exit(json_encode(array( 'jump' => $next_url)));
  16. }
  17. //Grab data
  18. $html = file_get_contents($base.$num[$page]);
  19. $html = str_replace('script', 'pre ', $html);
  20. $html .= '
  21. ';
  22. echo $html;
Copy code


source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template