Chinaunix
标题:
以前写的淘宝卖家卖出商品数量价格查询小工具
[打印本页]
作者:
nsnake
时间:
2010-02-24 15:31
标题:
以前写的淘宝卖家卖出商品数量价格查询小工具
本帖最后由 nsnake 于 2010-02-26 17:07 编辑
主要就是查看该卖家在指定时期内都卖了哪些商品,数量和价格
因为淘宝卖出的数据有一定的缓冲区,所以查询的数据并非100%是准确的,但如果你查询的时间段越长,数据会越精确
使用也比较简单
修改
my $url='http://rate.taobao.com/user-rate-a2af4af68a32e8f046e8703fed064284.htm';
复制代码
为你需要的店家信用评价的地址即可。
#!/usr/bin/perl -w
#####################################
#淘宝卖家卖出商品数量价格查询 #
#BY cgi.net <loveme1314@sakuras.cn> #
#http://blog.sakuras.cn #
#####################################
use strict;
use LWP::UserAgent;
use HTTP::Cookies;
use HTML::TreeBuilder;
#use HTTP::Request;
#use Data::Dumper;
$|=1;
my $url='http://rate.taobao.com/user-rate-a2af4af68a32e8f046e8703fed064284.htm';
#查询天数
my $day = 7;
#设置显示列表
my %conf = (
num => 1,
tite => 1,
price => 1,
url => 0,
);
###########################################################
$url =~ /rate\-(.*)\.htm/;
my $user = $1;
my @ns_headers = (
'User-Agent' => 'Mozilla/4.76 [en] (Win2000; U)',
'Accept' => 'image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, image/png, */*',
'Accept-Charset' => 'iso-8859-1,*,utf-8',
'Accept-Language' => 'en-US',
);
#只查看好评过的商品
our $good_url = "http://rate.taobao.com/user-rate-$user--detailed|1--goodNeutralOrBad|1--timeLine|-$day--receivedOrPosted|0--buyerOrSeller|0.htm#RateType";
our %count;
while ( $good_url )
{
#print '>>1' . $good_url ."\r\n";
_get_data ( $good_url );
}
#生成列表清单并排序
map { $count{$_}->{sort} = sprintf('%s', $count{$_}->{'num'} ) } keys %count;
my @marksorted = sort { $count{$b}->{sort} <=> $count{$a}->{sort} } keys %count;
foreach ( @marksorted )
{
$count{$_}->{'num'} = '' unless $conf{num} ;
$count{$_}->{'tite'} = '' unless $conf{tite} ;
$count{$_}->{'price'} = '' unless $conf{price} ;
$count{$_}->{'url'} = '' unless $conf{url} ;
print sprintf ("%u\t%s\t%s\t%s\r\n",$count{$_}->{'num'},$count{$_}->{'tite'},$count{$_}->{'price'},$count{$_}->{'url'});
}
exit;
sub _get_data
{
my $good_url_new = shift || exit;
#开始访问页面
my $browser=LWP::UserAgent->new;
my $tree = new HTML::TreeBuilder;
my $resp =$browser->get($good_url_new,@ns_headers);
die $resp->message ,$resp->status_line unless $resp->is_success;
$tree->parse( $resp->content );
#获取物品价格
our @prices;
foreach my $tmp2 ( $tree->look_down( '_tag' , 'span' , 'class' , 'price' ) )
{
push @prices , $tmp2;
}
#获取物品名称
foreach my $tmp1 ( $tree->look_down( '_tag' , 'p' , 'class' , 'exp' ) )
{
my $list = $tmp1->look_down('_tag', 'a');
my $tmp2 = shift @prices;
my $list2 = $tmp2->look_down('_tag', 'em');
#$list->dump();
#$list2->dump();
count($list->attr('title'),$list->attr('href'),$list2->as_text);
$tmp1->delete;
}
#获取总页数
my $pages = 0;
foreach ( $tree->look_down( '_tag', 'a',
sub {
if ($_[0]->as_HTML('<>&',' ',{}) =~ /\>\;\>\;/ig)
{$pages = $_[0]->attr('href')}
}
) ){};
$tree = undef;
#print '>>2' . $pages . "\r\n";
if ( $pages ) {
$good_url = $pages;
}
else{ $good_url = $pages ;}
}
sub count
{
my ($tite,$url,$price) = @_;
my $id = _return_id($url);
#print $id . "\n";
if ( exists $count{$id} )
{
++($count{$id}->{'num'}) ;
}
else{
$count{$id} = { 'num' =>1 , 'tite' => $tite , 'url' => $url ,'price' => $price };
}
}
sub _return_id
{
my $content = shift;
#$content =~ /auction1\.taobao\.com\/auction\/snap_detail\.htm\?trade_id=(\d+)&auction_id=([0-9a-z]+)/ig;
$content =~ /auction_id=([0-9a-z]+)/ig;
return $1;
}
复制代码
作者:
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