采集某个网站下的列表url及url的size
来源:互联网 发布:单片机与plc的区别知乎 编辑:程序博客网 时间:2024/06/01 09:40
<?php
/**
目的:采集某个网站下的列表url及url的size
使用说明,下载canphp2.0目录lib的http.class.php类,下载simple_html_dom.php
error.txt保存超时的url
list.txt保存列表url及url的size
error.txt保存记录所有不重复的url
*/
include ('Http.class.php');
include ('simple_html_dom.php');
//计数
$page = ! empty ( $_GET ['page'] ) ? $_GET ['page'] : 1;
//读取weburl.txt的所有连接
$pieces = getTextArray ();
if ($page == 1) {
$weburl = "http://product.cn.china.cn/suppliers/%B9%E3%D6%DD/";
} else {
$weburl = $pieces [$page - 1];
}
echo $weburl . "<br><br>";
$lista = $pieces;
//读取当前url的所有url包含/suppliers/的连接,读取当前url的size
$htmlcontent = Http::doGet ( $weburl );
if(!empty($htmlcontent)){
$html = str_get_html ( $htmlcontent );
foreach ( $html->find ( 'a' ) as $e ) {
if (strpos ( $e->href, "/suppliers/" ) && ! strstr ( $e->href, $weburl )) {
$lista [] = $e->href;
}
}
}
else{
$errorfile = "error.txt";
$error_str = $weburl . "\n";
file_put_contents ( $errorfile, $error_str, FILE_APPEND );
echo "<script language='javascript'>window.location.href='list_url_size_collect.php?page=" . $page . "'</script>";
}
$lista_new = array_unique ( $lista );
$listaSize = "";
$listaPer = "100";
foreach ( $html->find ( 'span.pageNum' ) as $e ) {
preg_match ( "/(\d+)/i", $e->outertext, $matches );
$listaSize = $matches [0];
}
$listaSize = $listaSize > 100 ? 100 : $listaSize;
//把当前url及当前url的size写进weburl.txt里
$listfile = "listurl.txt";
$listfile_str = $weburl . "@@@@" . $listaSize . "\n";
file_put_contents ( $listfile, $listfile_str, FILE_APPEND );
//把读取的不重复的url写进weburl.txt里
$webfile = "weburl.txt";
$webfile_str = "";
foreach ( $lista_new as $v ) {
if (! empty ( $v )) {
$webfile_str .= $v . "\n";
}
}
file_put_contents ( $webfile, $webfile_str );
$page ++;
//如果当前url不为空,continue跳转到当前页面,计数+1
if (! empty ( $weburl )) {
echo "<script language='javascript'>window.location.href='list_url_size_collect.php?page=" . $page . "'</script>";
} else {
echo $weburl . "<br>";
}
function getTextArray($filename = "weburl.txt") {
$urlcontent = file_get_contents ( $filename );
$pieces = explode ( "\n", $urlcontent );
array_pop ( $pieces );
return $pieces;
}
/**
目的:采集某个网站下的列表url及url的size
使用说明,下载canphp2.0目录lib的http.class.php类,下载simple_html_dom.php
error.txt保存超时的url
list.txt保存列表url及url的size
error.txt保存记录所有不重复的url
*/
include ('Http.class.php');
include ('simple_html_dom.php');
//计数
$page = ! empty ( $_GET ['page'] ) ? $_GET ['page'] : 1;
//读取weburl.txt的所有连接
$pieces = getTextArray ();
if ($page == 1) {
$weburl = "http://product.cn.china.cn/suppliers/%B9%E3%D6%DD/";
} else {
$weburl = $pieces [$page - 1];
}
echo $weburl . "<br><br>";
$lista = $pieces;
//读取当前url的所有url包含/suppliers/的连接,读取当前url的size
$htmlcontent = Http::doGet ( $weburl );
if(!empty($htmlcontent)){
$html = str_get_html ( $htmlcontent );
foreach ( $html->find ( 'a' ) as $e ) {
if (strpos ( $e->href, "/suppliers/" ) && ! strstr ( $e->href, $weburl )) {
$lista [] = $e->href;
}
}
}
else{
$errorfile = "error.txt";
$error_str = $weburl . "\n";
file_put_contents ( $errorfile, $error_str, FILE_APPEND );
echo "<script language='javascript'>window.location.href='list_url_size_collect.php?page=" . $page . "'</script>";
}
$lista_new = array_unique ( $lista );
$listaSize = "";
$listaPer = "100";
foreach ( $html->find ( 'span.pageNum' ) as $e ) {
preg_match ( "/(\d+)/i", $e->outertext, $matches );
$listaSize = $matches [0];
}
$listaSize = $listaSize > 100 ? 100 : $listaSize;
//把当前url及当前url的size写进weburl.txt里
$listfile = "listurl.txt";
$listfile_str = $weburl . "@@@@" . $listaSize . "\n";
file_put_contents ( $listfile, $listfile_str, FILE_APPEND );
//把读取的不重复的url写进weburl.txt里
$webfile = "weburl.txt";
$webfile_str = "";
foreach ( $lista_new as $v ) {
if (! empty ( $v )) {
$webfile_str .= $v . "\n";
}
}
file_put_contents ( $webfile, $webfile_str );
$page ++;
//如果当前url不为空,continue跳转到当前页面,计数+1
if (! empty ( $weburl )) {
echo "<script language='javascript'>window.location.href='list_url_size_collect.php?page=" . $page . "'</script>";
} else {
echo $weburl . "<br>";
}
function getTextArray($filename = "weburl.txt") {
$urlcontent = file_get_contents ( $filename );
$pieces = explode ( "\n", $urlcontent );
array_pop ( $pieces );
return $pieces;
}
- 采集某个网站下的列表url及url的size
- 网站的URL重写
- 网站的URL重写
- 网站的URL重写
- C#获取某个URL下网页的方法
- 获得页面url的某个url参数的方法
- 获得页面url的某个url参数的方法
- 获得页面url的某个url参数的值
- javascript获取url上的某个参数
- varnish 过滤某个参数的url
- yii2 strace 追踪 某个执行的url
- 获取url上某个参数的值
- 获取URL中的某个参数的方法
- JavaScript获取url某个参数的值
- 相关的技术网站URL
- 一些常用网站的 url
- 网站URL的设计规划
- 网站URL的设计规划
- POJ 1151 Atlantis(离散化+扫描线)
- T9输入法相关代码
- 解决url中文传参乱码问题
- linux memcache安装
- MyEclipse9.0集成SVN
- 采集某个网站下的列表url及url的size
- Java与数据库对应的日期类型
- Linux ls -l 命令详解
- 关于Servlet的一些小知识
- 常见vc错误 —unresolved external symbol __endthreadex
- 位运算
- Eclipse快捷键大全(转载)
- Android文件下载进度条的实现
- java 设计模式