免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 30173 | 回复: 84

以前写的淘宝卖家卖出商品数量价格查询小工具 [复制链接]

论坛徽章:
0
发表于 2010-02-24 15:31 |显示全部楼层
本帖最后由 nsnake 于 2010-02-26 17:07 编辑

主要就是查看该卖家在指定时期内都卖了哪些商品,数量和价格
因为淘宝卖出的数据有一定的缓冲区,所以查询的数据并非100%是准确的,但如果你查询的时间段越长,数据会越精确
使用也比较简单
修改
  1. my $url='http://rate.taobao.com/user-rate-a2af4af68a32e8f046e8703fed064284.htm';
复制代码
为你需要的店家信用评价的地址即可。


  1. #!/usr/bin/perl -w
  2. #####################################
  3. #淘宝卖家卖出商品数量价格查询     #
  4. #BY cgi.net <loveme1314@sakuras.cn> #
  5. #http://blog.sakuras.cn             #
  6. #####################################
  7. use strict;
  8. use LWP::UserAgent;
  9. use HTTP::Cookies;
  10. use HTML::TreeBuilder;
  11. #use HTTP::Request;
  12. #use Data::Dumper;
  13. $|=1;
  14. my $url='http://rate.taobao.com/user-rate-a2af4af68a32e8f046e8703fed064284.htm';
  15. #查询天数
  16. my $day = 7;
  17. #设置显示列表
  18. my %conf = (
  19.              num   => 1,
  20.              tite  => 1,
  21.              price => 1,
  22.              url   => 0,
  23.             );
  24. ###########################################################
  25.    $url =~ /rate\-(.*)\.htm/;
  26. my $user = $1;
  27. my @ns_headers = (
  28.                  'User-Agent' => 'Mozilla/4.76 [en] (Win2000; U)',
  29.                  'Accept' => 'image/gif, image/x-xbitmap, image/jpeg,
  30.                   image/pjpeg, image/png, */*',
  31.                   'Accept-Charset' => 'iso-8859-1,*,utf-8',
  32.                   'Accept-Language' => 'en-US',
  33.                  );
  34. #只查看好评过的商品
  35. our $good_url = "http://rate.taobao.com/user-rate-$user--detailed|1--goodNeutralOrBad|1--timeLine|-$day--receivedOrPosted|0--buyerOrSeller|0.htm#RateType";
  36. our %count;
  37. while ( $good_url )
  38.       {
  39.   #print '>>1' . $good_url ."\r\n";
  40.      _get_data ( $good_url );
  41.    }
  42. #生成列表清单并排序
  43. map { $count{$_}->{sort} = sprintf('%s', $count{$_}->{'num'} ) } keys %count;
  44. my @marksorted = sort { $count{$b}->{sort} <=> $count{$a}->{sort} } keys %count;
  45. foreach ( @marksorted )
  46.          {
  47.    $count{$_}->{'num'}   = '' unless $conf{num} ;
  48.          $count{$_}->{'tite'}  = '' unless $conf{tite} ;
  49.    $count{$_}->{'price'} = '' unless $conf{price} ;
  50.    $count{$_}->{'url'}   = '' unless $conf{url} ;
  51.    print sprintf ("%u\t%s\t%s\t%s\r\n",$count{$_}->{'num'},$count{$_}->{'tite'},$count{$_}->{'price'},$count{$_}->{'url'});
  52.    }
  53. exit;

  54. sub _get_data
  55. {
  56. my $good_url_new = shift || exit;
  57. #开始访问页面
  58. my $browser=LWP::UserAgent->new;
  59. my $tree = new HTML::TreeBuilder;
  60. my $resp =$browser->get($good_url_new,@ns_headers);
  61. die $resp->message ,$resp->status_line unless $resp->is_success;
  62.     $tree->parse( $resp->content );
  63. #获取物品价格
  64. our @prices;
  65. foreach my $tmp2 ( $tree->look_down( '_tag' , 'span' , 'class' , 'price' ) )
  66.               {
  67.                push @prices , $tmp2;
  68.                  }
  69. #获取物品名称
  70. foreach my $tmp1 ( $tree->look_down( '_tag' , 'p' , 'class' , 'exp' ) )
  71.                {
  72.                 my $list = $tmp1->look_down('_tag', 'a');
  73.     my $tmp2 = shift @prices;
  74.     my $list2 = $tmp2->look_down('_tag', 'em');
  75.     #$list->dump();
  76.     #$list2->dump();   
  77.     count($list->attr('title'),$list->attr('href'),$list2->as_text);
  78.     $tmp1->delete;
  79.                 }
  80.                
  81. #获取总页数
  82. my $pages = 0;
  83. foreach ( $tree->look_down( '_tag', 'a',
  84.                                     sub {
  85.                                             if ($_[0]->as_HTML('<>&',' ',{}) =~ /\&gt\;\&gt\;/ig)
  86.                                          {$pages = $_[0]->attr('href')}

  87.                                          }
  88.                         ) ){};
  89. $tree = undef;
  90. #print  '>>2' . $pages . "\r\n";
  91. if ( $pages ) {
  92.                     $good_url = $pages;
  93.           }
  94. else{ $good_url = $pages ;}
  95. }
  96. sub count
  97. {
  98. my ($tite,$url,$price) = @_;
  99. my $id = _return_id($url);
  100. #print $id . "\n";
  101. if ( exists $count{$id} )
  102.                   {
  103.                       ++($count{$id}->{'num'}) ;
  104.       }
  105. else{
  106.   $count{$id} = { 'num' =>1 , 'tite' => $tite , 'url' => $url ,'price' => $price };
  107.   }
  108. }
  109. sub _return_id
  110. {
  111.     my $content = shift;
  112.        #$content =~ /auction1\.taobao\.com\/auction\/snap_detail\.htm\?trade_id=(\d+)&auction_id=([0-9a-z]+)/ig;
  113.        $content =~ /auction_id=([0-9a-z]+)/ig;
  114.        return $1;
  115. }
复制代码

论坛徽章:
0
发表于 2010-02-24 15:48 |显示全部楼层
看看

论坛徽章:
0
发表于 2010-02-24 15:50 |显示全部楼层
有趣的小工具,lz思维够发散,这个感觉符合perl的用途,呵呵

论坛徽章:
0
发表于 2010-02-24 15:52 |显示全部楼层
qiaoqiao

论坛徽章:
78
双子座
日期:2013-10-15 08:50:09天秤座
日期:2013-10-16 18:02:08白羊座
日期:2013-10-18 13:35:33天蝎座
日期:2013-10-18 13:37:06狮子座
日期:2013-10-18 13:40:31双子座
日期:2013-10-22 13:58:42戌狗
日期:2013-10-22 18:50:04CU十二周年纪念徽章
日期:2013-10-24 15:41:34巨蟹座
日期:2013-10-24 17:14:56处女座
日期:2013-10-24 17:15:30双子座
日期:2013-10-25 13:49:39午马
日期:2013-10-28 15:02:15
发表于 2010-02-24 15:53 |显示全部楼层
学习下

论坛徽章:
0
发表于 2010-02-24 16:04 |显示全部楼层
我也看看

论坛徽章:
0
发表于 2010-02-24 16:04 |显示全部楼层
看看

论坛徽章:
0
发表于 2010-02-24 16:17 |显示全部楼层
帖子
    65
主题
    0
精华
    0
可用积分
    841  
专家积分
    0  
来自
    广州
在线时间
    269 小时
注册时间
    2009-10-19
最后登录
    2010-02-24

状态:...当前在线...

[博客] [短信]

论坛徽章:
0
发表于 2010-02-24 16:25 |显示全部楼层

论坛徽章:
0
发表于 2010-02-24 16:36 |显示全部楼层
呵呵 这个很有趣
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP