Chinaunix

标题: 以前写的淘宝卖家卖出商品数量价格查询小工具 [打印本页]

作者: nsnake    时间: 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. }
复制代码

作者: shaneqi    时间: 2010-02-24 15:48
看看
作者: ioerr    时间: 2010-02-24 15:50
有趣的小工具,lz思维够发散,这个感觉符合perl的用途,呵呵
作者: linuxty    时间: 2010-02-24 15:52
qiaoqiao
作者: yybmsrs    时间: 2010-02-24 15:53
学习下
作者: dahe_1984    时间: 2010-02-24 16:04
我也看看
作者: toniz    时间: 2010-02-24 16:04
看看
作者: hh9net    时间: 2010-02-24 16:17
帖子
    65
主题
    0
精华
    0
可用积分
    841  
专家积分
    0  
来自
    广州
在线时间
    269 小时
注册时间
    2009-10-19
最后登录
    2010-02-24

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

[博客] [短信]
作者: suntoltti    时间: 2010-02-24 16:25

作者: arigatuo    时间: 2010-02-24 16:36
呵呵 这个很有趣
作者: liht1981    时间: 2010-02-24 16:37
我来学习一下
作者: 不想在家喂猪    时间: 2010-02-24 16:51

作者: xxhacker    时间: 2010-02-24 18:36
look一下~~~~~~~~~~~
作者: lemontv    时间: 2010-02-24 19:57
看看。
作者: hantten    时间: 2010-02-24 20:08
- -!看看
作者: 黑色阳光_cu    时间: 2010-02-24 20:19
看看```````````
作者: moccot    时间: 2010-02-24 20:33
有趣的 看看
作者: alabos    时间: 2010-02-24 20:50
回复 1# nsnake


楼主辛苦了。 看看。
作者: cyagen    时间: 2010-02-24 20:54
回复 1# nsnake

see see
作者: blackold    时间: 2010-02-24 22:09

作者: sunhao0000    时间: 2010-02-24 22:10
kanxia
作者: radeon9900    时间: 2010-02-24 22:20
学习一下
作者: vgra    时间: 2010-02-25 09:10
回复 1# nsnake


    re
作者: Pro_sky    时间: 2010-02-25 09:53
CC
作者: kevindong    时间: 2010-02-25 10:47

作者: darking358    时间: 2010-02-25 12:56
ll
作者: biotyp    时间: 2010-02-25 13:51
学习一下.
作者: wpf8816528    时间: 2010-02-25 14:31
CC
作者: Ammon    时间: 2010-02-25 14:53
CC
作者: ddnnetddn    时间: 2010-02-25 14:55
回复 1# nsnake


   
作者: gaochong    时间: 2010-02-25 15:21

作者: jetgm    时间: 2010-02-25 15:29
提示: 作者被禁止或删除 内容自动屏蔽
作者: suxingwakeup    时间: 2010-02-25 15:49
看一下。
作者: root_wxt    时间: 2010-02-25 16:03

作者: saberllan    时间: 2010-02-25 16:14
看看
作者: xj_sir    时间: 2010-02-25 16:16
看看
作者: sunnygut    时间: 2010-02-25 16:17
thanks
作者: bleai    时间: 2010-02-25 16:35

作者: celise    时间: 2010-02-25 16:35
有趣的小工具
作者: x9x9    时间: 2010-02-25 16:37
学习一下~
作者: 小公猫    时间: 2010-02-25 16:39

作者: cjmcjmc    时间: 2010-02-25 17:02
看看
作者: Vinsion    时间: 2010-02-25 17:03
俺要下
作者: wisedan    时间: 2010-02-25 17:13
对perl还不是很熟 学习一下
作者: *梦*    时间: 2010-02-25 17:15

作者: 指水    时间: 2010-02-25 17:44

作者: 孙跃    时间: 2010-02-25 17:51
俺也看看
作者: mars531706    时间: 2010-02-25 17:53

好久没有回复
CU的风格都改了啊
作者: ccc77    时间: 2010-02-25 17:57
好呀。
作者: minirain    时间: 2010-02-25 18:11
回复 1# nsnake


    好东西一定要顶的!
作者: k_ewell    时间: 2010-02-25 19:39
不知道源码的话难道是处理URL中的内容?
作者: jy198435    时间: 2010-02-25 19:49
ssss
作者: whtech    时间: 2010-02-25 19:55

作者: sdsuper    时间: 2010-02-25 22:21
cc
作者: linuxmymail163c    时间: 2010-02-26 03:23
看看
作者: newbuding    时间: 2010-02-26 07:57
还要回复?真麻烦
作者: hhx1129    时间: 2010-02-26 08:39
回复 1# nsnake


    看看。
作者: gawk    时间: 2010-02-26 08:53

作者: csshrb2004    时间: 2010-02-26 09:05
好东西啊!
作者: souldemo    时间: 2010-02-26 09:24
ddddddddd
作者: sky-鹏    时间: 2010-02-26 09:39
看看,最近在搞淘宝
作者: aroline    时间: 2010-02-26 10:41
这个想法挺有创意
作者: htsmy    时间: 2010-02-26 10:44
学习一下
作者: aramy    时间: 2010-02-26 10:53
看看!
作者: drvial    时间: 2010-02-26 11:16

作者: saekil    时间: 2010-02-26 11:16
学习下!
作者: zhfg45    时间: 2010-02-26 13:04
学习学习
作者: linzi1128    时间: 2010-02-26 13:22
看一看
作者: 非凡公子    时间: 2010-02-26 13:36
perl写的?学习一下
作者: evaspring    时间: 2010-02-26 13:52
{:3_183:}
作者: xijK_1227    时间: 2010-02-26 14:12
学习一下
作者: brokencluster    时间: 2010-02-26 14:38
学习下
作者: cairb    时间: 2010-02-26 14:41
看看
作者: e0easy    时间: 2010-02-26 14:48
回复 1# nsnake


    好奇。。。看看。。。顺便学习下
作者: embededboy    时间: 2010-02-26 14:52
回复
作者: yangfei805    时间: 2010-02-26 15:13
真的哦
作者: npk    时间: 2010-02-26 15:17
谢谢楼主的代码和说明:wink:
作者: jiang_ocean    时间: 2010-02-26 16:24
咱也看一下。
作者: hzsjx    时间: 2010-02-26 16:25

作者: beyondfly    时间: 2010-02-26 21:48
LZ太厉害了
作者: yuhuohu    时间: 2010-03-05 09:09
好牛
作者: gigabyte    时间: 2010-03-06 23:13
学习学习
作者: huanhuolang    时间: 2010-08-30 14:26
看看~~~~~~~~
作者: brant_chen    时间: 2010-08-30 14:38
非常厉害!学习学习!
作者: i57110403    时间: 2012-11-09 16:09
路过,学习中。。。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2