1. <pre name="code" class="python">use LWP::UserAgent;
  2. use utf8;
  3. use DBI;
  4. use POSIX;
  5. use Data::Dumper;
  6. use HTML::TreeBuilder;
  7. use HTML::TreeBuilder::XPath;
  8. my $ua = LWP::UserAgent->new;
  9. $ua->timeout(10);
  10. $ua->env_proxy;
  11. $ua->agent("Mozilla/8.0");
  12. #my $response = $ua->get('http://data.10jqka.com.cn/financial/yjyg/date/2016-12-31/board/ALL/field/enddate/order/desc/page/1/ajax/1/');
  13. #my $response = $ua->get('http://data.10jqka.com.cn/financial/yjyg/');
  14. my @array=('2016-12-31','2016-03-31','2015-12-31','2015-09-30','2015-06-30','2015-03-31','2014-12-31','2014-09-30','2014-03-31');
  15.  
  16. foreach (@array){
  17. print "\$_ is $_\n";
  18. my $url="http://data.10jqka.com.cn/financial/yjyg/date/$_/board/ALL/field/enddate/order/desc/page/1/ajax/1/";
  19. print "\$url is $url\n";
  20. my $response = $ua->get($url);
  21. if ($response->is_success) {
  22. open DATAFH,">data.html" || die "open data file failed:$!";
  23. print DATAFH "<html>";
  24. print DATAFH "\n";
  25. print DATAFH $response->decoded_content; # or whatever
  26. print DATAFH "</html>";
  27. print DATAFH "\n";
  28. };
  29. close DATAFH;
  30. unlink("ths.html");
  31. system('cp data.html ths.html');
  32. $tree= HTML::TreeBuilder::XPath->new;
  33. $tree->parse_file( "ths.html");
  34.  
  35. my $title="$_";
  36. #my $title= $tree->findvalue('/html/body//span[@class="text-value"]');
  37. print "\$title is $title\n";
  38. my @pages="";
  39. my @titlepage="";
  40. $max="";
  41. my @pages=$tree->find_by_tag_name('a');
  42. print "\@pages is @pages\n";
  43. #@urlall除了包含每个类别的文章,还包含阅读排行里的文章
  44. foreach (@pages) {
  45. @titlepage = $_->attr('page');
  46. foreach (@titlepage) {
  47. if ($_){
  48. if ( $_ > $max ){
  49. $max=$_;
  50. }; ###获取版块中每个页面的url
  51. };
  52. };
  53. };
  54. unless ($max){$max=1};
  55. print "\$max is $max\n";
  56. sleep (5);
  57.  
  58. for ($m=1;$m<=$max; $m++){
  59.  
  60. my $url="http://data.10jqka.com.cn/financial/yjyg/date/$_/board/ALL/field/enddate/order/desc/page/$m/ajax/1/";
  61. my $response = $ua->get("$url");
  62. if ($response->is_success) {
  63. open DATAFH,">data.html" || die "open data file failed:$!";
  64. print DATAFH "<html>";
  65. print DATAFH "\n";
  66. print DATAFH $response->decoded_content; # or whatever
  67. print DATAFH "</html>";
  68. print DATAFH "\n";
  69. close DATATH;
  70. };
  71. unlink("ths.html");
  72. system('cp data.html ths.html');
  73. $tree= HTML::TreeBuilder::XPath->new;
  74. $tree->parse_file( "ths.html");
  75.  
  76. my @arr1= $tree->find_by_tag_name("tr") ;
  77. #shift @arr1;
  78. foreach my $row ( @arr1) {
  79. my @arr2= $row->content_list;
  80.  
  81. my $str1= $arr2[0]->as_text;
  82. my $str2= $arr2[1]->as_text;
  83. my $str3= $arr2[2]->as_text;
  84. my $str4= $arr2[3]->as_text;
  85. my $str5= $arr2[4]->as_text;
  86. my $str6= $arr2[5]->as_text;
  87. my $str7= $arr2[6]->as_text;
  88. my $str8= $arr2[7]->as_text;
  89. print $str1, $str2, $str3, $str4, $str5, $str6, $str7,$str8."\n";
  90. open( E, ">>", "$title-$m.txt" );
  91. print E ($str1."|".$str2."|".$str3."|".$str4."|".$str5."|".$str6."|".$str7."|".$str8."\n");
  92. close E;
  93.  
  94. }
  95. }
  96. }
  1.  

perl 爬取上市公司业绩预告的更多相关文章

  1. Perl爬取江西失信执行

    #! /usr/bin/perl use strict; use Encode qw(encode decode); binmode(STDIN,":encoding(utf8)" ...

  2. Perl爬取铁路违章旅客信息

    #! /usr/bin/perl use strict; use Encode qw(encode decode); binmode(STDIN,":encoding(utf8)" ...

  3. perl 爬取某理财网站产品信息

    use LWP::UserAgent; use utf8; use DBI; $user="root"; $passwd="xxxxx"; $dbh=" ...

  4. perl 爬取数据<1>

    use LWP::UserAgent; use POSIX; use DBI; $user="root"; $passwd="11111111"; $dbh=& ...

  5. perl 爬取csdn

    <pre name="code" class="python">use LWP::UserAgent; use POSIX; use HTML::T ...

  6. perl 爬取同花顺数据

    use LWP::UserAgent; use utf8; use DBI; $user="root"; $passwd='xxx'; $dbh=""; $db ...

  7. Python爬取CSDN博客文章

    0 url :http://blog.csdn.net/youyou1543724847/article/details/52818339Redis一点基础的东西目录 1.基础底层数据结构 2.win ...

  8. 用WebCollector制作一个爬取《知乎》并进行问题精准抽取的爬虫(JAVA)

    简单介绍: WebCollector是一个无须配置.便于二次开发的JAVA爬虫框架(内核),它提供精简的的API.仅仅需少量代码就可以实现一个功能强大的爬虫. 怎样将WebCollector导入项目请 ...

  9. Java爬虫_资源网站爬取实战

    对 http://bestcbooks.com/  这个网站的书籍进行爬取 (爬取资源分享在结尾) 下面是通过一个URL获得其对应网页源码的方法 传入一个 url  返回其源码 (获得源码后,对源码进 ...

随机推荐

  1. Linux内核中的list用法和实现分析

    这些天在思考知识体系的完整性,发现总是对消息队列的实现不满意,索性看看内核里面的链表实现形式,这篇文章就当做是学习的i笔记吧.. 内核代码中有很多的地方使用了list,而这个list的用法又跟我们平时 ...

  2. Continue

    Continue 其作用为结束本次循环.即跳出循环体中下面尚未执行的语句. 对于while循环,继续求解循环条件. 对于for循环程序流程接着求解for语句头中的第三个部分expression表达式. ...

  3. surface 其实是UEFI与BIOS并存,借用官网的进入方法(少有更改)

    surface 其实是UEFI与BIOS并存,借用官网的进入方法(少有更改) 第一种: 1.       Swipe in from the right edge of the screen, and ...

  4. linux下修改.bash_profile立即生效的三种方法

    1 . .bash_profile 2 source .bash_profile 3 exec bash --login

  5. 怎么限制Google自己主动调整字体大小

    Google默认的字体大小是12px,当样式表中font-size<12px时,或者没有明白指定字体大小,则在chrome浏览器里字体显示是12px. 近期在写代码玩的时候,我也碰到了 在FF和 ...

  6. WCF遇到Oracle问题

    解决 选中下图中对网站和项目使用IIS….64位版

  7. Oracle集合操作函数:union、intersect、minus

    [转]Oracle集合操作函数:union.intersect.minus 集合操作符专门用于合并多条select 语句的结果,包括:UNION, UNION ALL, INTERSECT, MINU ...

  8. InnoDB的配置

    http://www.cnblogs.com/szx_rencaijob/archive/2010/04/28/1723211.html 推荐InnoDB的配置(1G内存情况,主要运行mysql服务器 ...

  9. leetcode String to Integer (atoi) python

    class Solution(object): def myAtoi(self, str): """ :type str: str :rtype: int "& ...

  10. Java 内省机制

    一.内省 内省(Introspector) 是Java 语言对 JavaBean 类属性.事件的一种缺省处理方法.JavaBean是一种特殊的类,主要用于传递数据信息,这种类中的方法主要用于访问私有的 ...