Perl 腾讯股票信息收集

Perl 腾讯股票信息收集,第1张

概述之前的新浪股票脚本信息不太全,参考前面一篇文章腾讯股票接口,写了一个更加方便的,信息比较全的。看代码: use utf8;use Encode;use strict;use warnings;use LWP::UserAgent;use threads (exit => 'threads_only',);use threads::shared;use constant URL =

之前的新浪股票脚本信息不太全,参考前面一篇文章腾讯股票接口,写了一个更加方便的,信息比较全的。看代码:

use utf8;use Encode;use strict;use warnings;use LWP::UserAgent;use threads (exit => 'threads_only',);use threads::shared;use constant URL	=> 'http://qt.gtimg.cn/q=';use constant PROXY	=> 'http://10.40.14.56:80'; #使用代理修改此处并去掉下边代码中的注释use constant MAxnuMBER	=> 50; #腾讯每次最多取60个左右的股票信息,设置一个整数,http GET中使用use constant CONfig	=> 'detail';use constant ColUMN	=> qw(1 2 3 4 5 7 8 10 9 19 20 31 32 36 37 38 39 46 44 45); #要显示的列,自己根据需要修改use constant ORDER	=> 2; #要排序的列my @result : shared 	= ();my @stockList 		= (	sub { map {"sh$_"} ('600001' .. '602100') }->(),sub { map {"sz$_"} ('000001' .. '001999') }->(),sub { map {"sz$_"} ('002001' .. '002999') }->(),sub { map {"sz$_"} ('300001' .. '300400') }->(),);my %config = (	detail => {		method => sub { @_ },0 	=> '未知',1 	=> '名字',2 	=> '代码',3 	=> '当前价格',4 	=> '昨收',5 	=> '今开',6 	=> '成交量',7 	=> '外盘',8 	=> '内盘',9 	=> '买一',10 	=> '买一量',19 	=> '卖一',20 	=> '卖一量',29 	=> '最近逐笔成交',30 	=> '时间',31 	=> '涨跌',32 	=> '涨跌%',33 	=> '最高',34 	=> '最低',35 	=> '价格/成交量(手)/成交额',36 	=> '成交量',37 	=> '成交:万',38 	=> '换手率%',39 	=> '市盈率',40 	=> '',41 	=> '最高',42 	=> '最低',43 	=> '振幅%',44 	=> '流通市值',45 	=> '总市值',46 	=> '市净率',47 	=> '涨停价',48 	=> '跌停价',},);GetStocks();@result = sort { ($a->[ORDER] || 0) <=> ($b->[ORDER] || 0) } @result; #可以使用grep添加更多过滤条件PrintStock();=headGet stock information from QQ=cutsub GetStockInfomation{	return unless @_;		my $ua = LWP::UserAgent->new();	# $ua->proxy('http',PROXY);		my $res = $ua->get(URL.join(',',$config{&CONfig}{method}->(@_)));	if($res->is_success){		for(split /;/,$res->content){			if(/"(.+)"/){				my @tmp = split /~/,;				push @result,shared_clone(\@tmp);			}		}	}}sub GetStocks{	while(my @tmp = splice @stockList,MAxnuMBER){		threads->create(\&GetStockInfomation,@tmp);	}	# $_->join() for threads->List();	while(threads->List()){		$_->join for threads->List(threads::joinable);	}}=headPrint stock information=cutsub PrintStock{	my $j = 0;	for(@result){		unless($j++ % MAxnuMBER){			print "\n";			# for my $col (ColUMN){			# 	printf "%10s",encode('gb2312',$config{&CONfig}{$col});			# }			printf "%10s" x ColUMN,map {encode('gb2312',$config{&CONfig}{$_})} ColUMN;			print "\n",'=' x 10 x ColUMN,"\n";		}		# for my $col (ColUMN){		# 	printf "%10s",$_->[$col];		# }		printf "%10s" x ColUMN,@$_[ColUMN];		print "\n";	}	print "\nTotal: ",$#result;}

输出:

总结

以上是内存溢出为你收集整理的Perl 腾讯股票信息收集全部内容,希望文章能够帮你解决Perl 腾讯股票信息收集所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1292091.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-10
下一篇2022-06-10

发表评论

登录后才能评论

评论列表(0条)

    保存