对网站的代码采集实例

1.采集的网站:http://www.abnova.com/support/publication.asp

2. 相关的代码:列表(规则采集)页面使用:phpQuery.php,可以参考:PHP curl_setopt函数用法介绍中篇

3.产品详情页面:信息(不规则采集),参考代码如下:

<?php
header(‘Content-Type:text/html;charset=UTF-8‘);
include ‘phpQuery/phpQuery.php‘;
set_time_limit(0);
$id = isset($_GET[‘id‘]) ? intval($_GET[‘id‘]) : 1;

$listArr = file(‘list.txt‘);

if (!array_key_exists($id,$listArr)){
    echo ‘finished‘;
    exit;
}

$url = preg_replace(‘/[\r\n]+/‘,‘‘,$listArr[$id]);
phpQuery::newDocumentFile($url);

$artList = pq("#sub_product_info");
echo ‘<pre>‘;

foreach($artList as $li){
    $data = array();
    $datacode = array();
    $datacode = explode(‘=‘,$url);
    $data[‘code‘] = $datacode[1];
    $one = ‘‘;
    $one_a = ‘‘;
    $one_a = pq($li)->find("#10000 b")->html();
    $one_a = trim(strip_tags($one_a));
    if($one_a == ‘Product Description:‘){
        // echo 1;
     $one = pq($li)->find(‘#10000 li‘)->eq(1)->html();
     $one =  trim(strip_tags($one));
     echo "Product Description:   ".$one;
    }else{
        echo "Product Description:   ".$one;
        // echo "wrong!<br/>";
    }
    $data[‘Description‘] = $one;
     echo ‘<br/>‘;
    #########################
    $two = ‘‘;
    $two_a = ‘‘;
    $two_a = pq($li)->find("#90000 b")->html();
    $two_a = trim(strip_tags($two_a));
    if($two_a == ‘Immunogen:‘){

     $two = pq($li)->find(‘#90000 li‘)->eq(1)->html();
     $two =  trim(strip_tags($two));
     echo "Immunogen:   ".$two;   

    }else{
        echo "Immunogen:   ".$two;
        // echo "wrong<br/>";
    }
    $data[‘Immunogen‘] = $two;
     echo ‘<br/>‘;
    #########################
    $three = ‘‘;
    $three_a = ‘‘;
    $three_a = pq($li)->find("#110000 b")->html();
    $three_a = trim(strip_tags($three_a));
    if($three_a == ‘Host:‘){

     $three = pq($li)->find(‘#110000 li‘)->eq(1)->html();
     $three =  trim(strip_tags($three));
     echo "Host:   ".$three;   

    }else{
        echo "Host:   ".$three;
        // echo "wrong<br/>";
    }
    $data[‘Host‘] = $three;
     echo ‘<br/>‘;
     #########################
     $four = ‘‘;
     $four_a = ‘‘;
    $four_a = pq($li)->find("#130000 b")->html();
    $four_a = trim(strip_tags($four_a));
    if($four_a == ‘Reactivity:‘){

     $four = pq($li)->find(‘#130000 li‘)->eq(1)->html();
     $four =  trim(strip_tags($four));
     echo "Reactivity:   ".$four;   

    }else{
        echo "Reactivity:   ".$four;
        // echo "wrong<br/>";
    }
    $data[‘Reactivity‘] = $four;
     echo ‘<br/>‘;
     #########################
    $five = ‘‘;
    $five_a =‘‘;
    $five_a = pq($li)->find("#240000 b")->html();
    $five_a = trim(strip_tags($five_a));
    if($five_a == ‘Isotype:‘){

     $five = pq($li)->find(‘#240000 li‘)->eq(1)->html();
     $five =  trim(strip_tags($five));
     echo "Isotype:   ".$five;   

    }else{
        echo "Isotype:   ".$five;
        // echo "wrong<br/>";
    }
    $data[‘Isotype‘] = $five;
     echo ‘<br/>‘;
     #########################

    $six = ‘‘;
    $six_a = ‘‘;
    $six_a = pq($li)->find("#290000 b")->html();
    $six_a = trim(strip_tags($six_a));
    if($six_a == ‘Quality Control Testing:‘){

     $six_all = pq($li)->find(‘#290000 li‘)->eq(1)->html();
     $six_all =  trim(strip_tags($six_all,"<br>"));
     // $six_all = str_replace("<br><br><br/>",‘###‘,)
     $six_arr = explode("<br><br><br>",$six_all);
     // var_dump($six_arr);
     $six = trim($six_arr[0]);
     echo "Quality Control Testing:    ".$six;   

    }else{
        echo "Quality Control Testing:    ".$six;
        // echo "wrong<br/>";
    }
    $data[‘Testing‘] = $six;
     echo ‘<br/>‘;
     echo ‘<hr/>‘;
     #########################

     $wh_11 = ‘‘;
     $wh_11 = pq($li) -> find(".part")->eq(2)->find(".first_title b")->html();
     $wh_11 = trim(strip_tags($wh_11));
     echo "APP:   ".$wh_11;
     echo ‘<br/>‘;

     $wh_22 = ‘‘;
     $wh_22 = pq($li) -> find(".part")->eq(2)->find("ul")->eq(1)->find("li")->eq(0)->html();
     $wh_22 = trim(strip_tags($wh_22));
     echo "Western:   ".$wh_22;
     echo ‘<br/>‘;

     $wh_33 = ‘‘;
     $wh_33 = pq($li) -> find(".part")->eq(2)->find("ul")->eq(2)->find("li")->eq(0)->html();
     $wh_33 = trim(strip_tags($wh_33));
     echo "Western Blot:   ".$wh_33;
     echo ‘<br/>‘;

     $wh_44 = ‘‘;
     $wh_44 = pq($li) -> find(".part")->eq(2)->find("ul")->eq(3)->find("li")->eq(0)->html();
     $wh_44 = trim(strip_tags($wh_44));
     echo "Immunohistochemistry:    ".$wh_44;
     echo ‘<br/>‘;

     $wh_55 = ‘‘;
     $wh_55 = pq($li) -> find(".part")->eq(2)->find("ul")->eq(4)->find("li")->eq(0)->html();
     $wh_55 = trim(strip_tags($wh_55));
     echo "Immunofluorescence:    ".$wh_55;
     echo ‘<br/>‘;

     $wh_66 = ‘‘;
     $wh_66 = pq($li) -> find(".part")->eq(2)->find("ul")->eq(5)->find("li")->eq(0)->html();
     $wh_66 = trim(strip_tags($wh_66));
     echo "Sandwich ELISA:   ".$wh_66;
     echo ‘<br/>‘;

     $wh_77 = ‘‘;
     $wh_77 = pq($li) -> find(".part")->eq(2)->find("ul")->eq(6)->find("li")->eq(0)->html();
     $wh_77 = trim(strip_tags($wh_77));
     echo "ELISA:   ".$wh_77;
     echo ‘<br/>‘;
    $app = array();
    $appstr = ‘‘;
    if ($wh_22 != ‘‘) $app[‘w1‘] = $wh_22;
    if ($wh_33 != ‘‘) $app[‘w2‘] = $wh_33;
    if ($wh_44 != ‘‘) $app[‘w3‘] = $wh_44;
    if ($wh_55 != ‘‘) $app[‘w4‘] = $wh_55;
    if ($wh_66 != ‘‘) $app[‘w5‘] = $wh_66;
    if ($wh_77 != ‘‘) $app[‘w6‘] = $wh_77;
    echo $appstr = implode(‘,‘,$app);
    $data[‘app‘] = $appstr;
     echo ‘<hr/>‘;
     #########################
     // $length = pq($li) -> find(".part")->eq(3)->find("ul")->find("li")->html();
     // $length = trim(strip_tags($length,‘<b>‘));
     // $length = str_replace("<b>","####",$length);
     // // $length = str_replace("</b>",",",$length);
     // echo $length;
     // $arr = explode(",",$length);
     // var_dump($arr);

     // foreach($length as $list){
     //  echo $list;
     //  // exit;
     // }
      echo ‘<hr/>‘;
     echo ‘<br/>‘;

     $heng_11 = ‘‘;
     $heng_11_a = ‘‘;
     $heng_11_a = pq($li) -> find(".part")->eq(3)->find("ul")->eq(1)->find("li")->eq(0)->find("b")->html();
     $heng_11_a = trim(strip_tags($heng_11_a));

     if($heng_11_a == ‘Entrez GeneID:‘){
      $heng_11 = pq($li) -> find(".part")->eq(3)->find("ul")->eq(1)->find("li")->eq(1)->find("a")->html();
      $heng_11 = trim(strip_tags($heng_11));
      echo "Entrez GeneID:   ".$heng_11;
     }else{
         echo "Entrez GeneID:   ".$heng_11;
     }
    $data[‘GeneID‘] = $heng_11;
     echo ‘<br/>‘;

     $heng_22 = ‘‘;
     $heng_22_a = ‘‘;
     $heng_22_a = pq($li) -> find(".part")->eq(3)->find("ul")->eq(2)->find("li")->eq(0)->find("b")->html();
     $heng_22_a = trim(strip_tags($heng_22_a));

     if($heng_22_a == ‘GeneBank Accession#:‘){
     $heng_22 = pq($li) -> find(".part")->eq(3)->find("ul")->eq(2)->find("li")->eq(1)->find("a")->html();
     $heng_22 = trim(strip_tags($heng_22));
     echo "GeneBank Accession#:   ".$heng_22;
     }else{
         echo "GeneBank Accession#:   ".$heng_22;
     }
     $data[‘GeneBank Accession‘] = $heng_22;
     echo ‘<br/>‘;

     $heng_33 = ‘‘;
     $heng_33_a = ‘‘;
     $heng_33_a = pq($li) -> find(".part")->eq(3)->find("ul")->eq(3)->find("li")->eq(0)->find("b")->html();
     $heng_33_a = trim(strip_tags($heng_33_a));

     if($heng_33_a == ‘Protein Accession#:‘){
     $heng_33 = pq($li) -> find(".part")->eq(3)->find("ul")->eq(3)->find("li")->eq(1)->find("a")->html();
     $heng_33 = trim(strip_tags($heng_33));
     echo "Protein Accession#:   ".$heng_33;
     }else{
         echo "Protein Accession#:   ".$heng_33;
     }
     $data[‘Protein Accession‘] = $heng_33;
     echo ‘<br/>‘;

      $heng_44 = ‘‘;
      $heng_44_a = ‘‘;
      $heng_44_a = pq($li) -> find(".part")->eq(3)->find("ul")->eq(4)->find("li")->eq(0)->find("b")->html();
      $heng_44_a = trim(strip_tags($heng_44_a));
      if($heng_44_a == ‘Gene Name:‘){
        $heng_44 = pq($li) -> find(".part")->eq(3)->find("ul")->eq(4)->find("li")->eq(1)->html();
         $heng_44 = trim(strip_tags($heng_44));
         echo "Gene Name:   ".$heng_44;
      }else{
          echo "Gene Name:    ".$heng_44;
      }
    $data[‘Gene Name‘] = $heng_44;
     echo ‘<br/>‘;

      $heng_55 = ‘‘;
      $heng_55_a = ‘‘;
      $heng_55_a = pq($li) -> find(".part")->eq(3)->find("ul")->eq(5)->find("li")->eq(0)->find("b")->html();
      $heng_55_a = trim(strip_tags($heng_55_a));

      if($heng_55_a == ‘Gene Alias:‘){
        $heng_55 = pq($li) -> find(".part")->eq(3)->find("ul")->eq(5)->find("li")->eq(1)->html();
        $heng_55 = trim(strip_tags($heng_55));
        echo "Gene Alias:   ".$heng_55;
      }else{
          echo "Gene Alias:  ".$heng_55;
      }
$data[‘Gene Alias‘] = $heng_55;

     echo ‘<br/>‘;

      $heng_66 = ‘‘;
      $heng_66_a = ‘‘;
      $heng_66_a = pq($li) -> find(".part")->eq(3)->find("ul")->eq(7)->find("li")->eq(0)->find("b")->html();
      $heng_66_a = trim(strip_tags($heng_66_a));
      if($heng_66_a == ‘Omim ID:‘){
        $heng_66 = pq($li) -> find(".part")->eq(3)->find("ul")->eq(7)->find("li")->eq(1)->html();
        $heng_66 = trim(strip_tags($heng_66));
        echo "Omim ID:  ".$heng_66;
      }else{
          echo "Omim ID:  ".$heng_66;
      }
$data[‘Omim ID‘] = $heng_66;
     echo ‘<br/>‘;

      $heng_77 = ‘‘;
      $heng_77_a = ‘‘;
      $heng_77_a = pq($li) -> find(".part")->eq(3)->find("ul")->eq(8)->find("li")->eq(0)->find("b")->html();
      $heng_77_a = trim(strip_tags($heng_77_a));
      if($heng_77_a == ‘Gene Ontology:‘){
        $heng_77 = pq($li) -> find(".part")->eq(3)->find("ul")->eq(8)->find("li")->eq(1)->find("a")->html();
        $heng_77 = trim(strip_tags($heng_77));
        echo "Gene Ontology:   ".$heng_77;
      }else{
          echo "Gene Ontology:   ".$heng_77;
      }
    $data[‘Gene Ontology‘] = $heng_77;

     # 获取文献
     $rarr = array();
     $Reference = ‘‘;
     if (preg_match(‘/Publication Reference/‘,$li->textContent)){
         preg_match_all(‘/Publication Reference(.*?)Applications/‘,preg_replace(‘/[\r\n]+/‘,‘‘,$li->textContent),$rarr);
     }
    $Reference = $rarr[1][0];
    $data[‘Reference‘] = $Reference;

    $rarr = array();
    print_r($data);

    # 写入文件
    $handle = fopen(‘list-new.csv‘,‘a‘);
    fputcsv($handle,$data);
    fclose($handle);

}

?>
<script>
function JumpUrl(){
    location.href=‘?id=<?php echo ($id+1);?>‘;
}
setTimeout(‘JumpUrl()‘,0);
</script>
时间: 2024-08-05 21:17:18

对网站的代码采集实例的相关文章

css3购物网站商品文字提示实例

css3购物网站商品文字提示实例先来看效果图:<ignore_js_op> 当鼠标划过图片时,有着泰迪熊黑色长方形的背景就会出现.来看HTML5+CSS3代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>购物网站商品文字提示</title> <style type="te

QQ登录集成到自己网站php代码(转载)

我们现在在各大网站论坛都可以看到点击一个QQ图标就可以利用自己的QQ号在网站进行登录了,下面我来告诉你一段QQ登录集成到自己网站php代码,有需要的朋友可参考. 1.打开open.qq.com 添加创建应用:->输入常规的数据,你会看到对应的APP ID和KEY值,这是对你身份证的唯一的验证. 2.打开 http://connect.qq.com/manage/ 点击->添加网站->输入相关信息,这里比较特别注意的是,回调地址那里填上你域名就可以了以上申核需要一到两天时间,耐心等待. 3

SEO之HTML优化:让你的网站HTML代码更符合SEO规范

摘要HTML优化是网站内部优化的重点,可能对SEO新手来说,容易忽略.符合搜索引擎习惯的HTML代码是极利于SEO的,可以让你的网站获得更好的搜索引擎排名.如何制作一个标准的HTML网页,如何做HTML优化,本文将为你详细阐述. 一直想写下SEO中关于HTML优化方面的的文章,总算空出这部分时间来了.其实,HTML优化应该是网站内部优化的重点,每个SEOer都需高度重视.根据本人多年实战经验,一般做过HTML优化的网站上线后,相关关键词都可以获得一个不错的搜索引擎排名.显然,符合搜索引擎习惯的H

[JS,NodeJs]个人网站效果代码集合

上次发的个人网站效果代码集合: 代码集合: 1.彩色文字墙[鼠标涟漪痕迹] 2.彩色旋转圆环 [模仿http://www.moma.org/interactives/exhibitions/2012/centuryofthechild/中间部分效果, 那个走路的孩子技术很简单,和以前的春分秋分Google的Doodles类似,就没有模仿,换成一个头像] 3.视屏拼图 4.百度地图api简单应用集合 5.财经数据 6.天气预报 [nodejs搭建,express框架,nodejs简单页面抓取,JS

使用prismjs为网站添加代码高亮功能

prismjs 是一款轻量.可扩展的代码语法高亮库,使用现代化的 Web 标准构建,使用 Prismjs 可以快速为网站添加代码高亮功能,支持超过113中编程语言,还支持多种插件,是简洁.高效的代码高亮解决方案.科技爱好者博客就是使用了Prism.js 实现漂亮的代码语法高亮功能,本文教你如何在wordpress上快速使用Prismjs实现代码高亮. 一.下载JS和CSS文件并上传到网站根目录. 在Prismjs网站下载页面下载需要的JS和CSS文件,下载页面: http://prismjs.c

SonarQube4.4+Jenkins进行代码检查实例之三-单元测试分析

作者:张克强    作者微博:张克强-敏捷307 在 <SonarQube4.4+Jenkins进行代码检查实例之一> 中介绍了不编译只检查的方式. 在<SonarQube4.4+Jenkins进行代码检查实例之二>中介绍了编译并检查编译结果的方式. 本文来介绍如何利用SonarQube来分析单元测试.最新推荐在分析插件是Jacoco. 当然要进行单元测试,首先单元测试得到了书写,能够本地执行得到结果.本示例采用Maven的典型结构. 1,配置Maven,在maven的conf目录

C/C++代码检视实例

相关文章链接如下: 微软过桥问题与测试人员素养 等价类分法 新解 测试用例设计中的NP难题 90%程序员写不出无BUG的二分查找程序? C/C++代码检视要点 4.1             代码检视实例 看完上面的评审检视要点后,也许有些读者已经急切地想找一些代码来试验一下看能否通过上面的内容来提高自己的检视能力.下面就讲几个代码检视的实例,请读者在看这些实例时先不要看后面的分析,自己先拿张纸边看代码边把自己能够发现的问题记录下来,然后再和后面的分析进行比较.如果能够发现后现分析中没有提及的问

SonarQube4.4+Jenkins进行代码检查实例之三-单元測试分析

作者:张克强    作者微博:张克强-敏捷307 在 <SonarQube4.4+Jenkins进行代码检查实例之中的一个> 中介绍了不编译仅仅检查的方式. 在<SonarQube4.4+Jenkins进行代码检查实例之二>中介绍了编译并检查编译结果的方式. 本文来介绍怎样利用SonarQube来分析单元測试.最新推荐在分析插件是Jacoco. 当然要进行单元測试,首先单元測试得到了书写,可以本地运行得到结果. 本演示样例採用Maven的典型结构. 1,配置Maven,在maven

SonarQube4.4+Jenkins进行代码检查实例之二

在 <SonarQube4.4+Jenkins进行代码检查实例之一> 中介绍了不编译只检查的方式. 但是有些代码检查需要使用字节码,比如Findbugs的检查依赖于字节码,实例一中只提取源代码,就不能进行Findbugs的检查. 要进行Findbugs检查就需要编译.以下实例操作来演示如何搭建 1,首先当然是要下载最新的Findbugs    http://docs.codehaus.org/display/SONAR/FindBugs+Plugin  ,当前最新版是V3.0,  suppor