perl 爬取数据<1>
来源:互联网 发布:java程序员推荐笔记本 编辑:程序博客网 时间:2024/05/21 17:11
use LWP::UserAgent;use POSIX;use DBI; $user="root"; $passwd="11111111"; $dbh=""; $dbh = DBI->connect("dbi:mysql:database=zjzc_vote;host=11.55.5.57;port=3306",$user,$passwd) or die "can't connect to database ". DBI-errstr; $dbh->do("SET NAMES utf8"); use utf8;use HTML::TreeBuilder;if (-f "data.html"){open FILE,">data.html";close FILE;}open DATAFH,">>data.html" || die "open data file failed:$!"; my $ua = LWP::UserAgent->new;$ua->timeout(10);$ua->env_proxy;$ua->agent("Mozilla/8.0");my $response = $ua->get('https://licai.yingyinglicai.com/product/list.htm');if ($response->is_success) { print DATAFH $response->decoded_content; # or whatever# print $response->decoded_content; # or whatever use HTML::TreeBuilder::XPath; my $tree= HTML::TreeBuilder::XPath->new; $tree->parse_file( "data.html"); my @nb=$tree->findvalues( '/html/body//div[@class="fresh"]'); foreach (@nb){print "Product is $_\n"; chomp $_; my $XDATE = strftime("%Y%m%d%H%M%S",localtime()); my $sql = "SELECT count(*) FROM p2p_product where productname='$_' and cname='yylc'"; my $sth = $dbh->prepare($sql); $sth->execute(); my $count = $sth->fetchrow_array(); if ($count == 0 ){ my $host = "http://211.149.197.95:8888/sms.aspx?action=send&userid=74&account=SDK00026&password=960579&mobile=18957175628&content=$_&sendTime=&extno=";my $response = $ua->get($host); $ua->default_headers;if ($response->is_success) { print $response->decoded_content; # or whatever} $dbh->do("insert into p2p_product values ('$_','$XDATE','yylc')") or $!; } }; } else { die $response->status_line; };
0 0
- perl 爬取数据<1>
- perl 爬取同花顺数据
- perl 爬取csdn
- perl 爬取 find_by_tag_name
- perl 爬取 csdn 博客
- perl 爬取铜板街
- perl 爬取上市公司业绩预告
- perl 循环类选择器 ,爬取内容
- perl 爬取html findvalues 方法
- perl取文件大小
- perl取文件大小 .
- 爬取高考数据
- 证券数据爬取
- php爬取数据
- 动态数据爬取
- python爬取数据
- htmlunit爬取数据
- admob数据爬取
- 把常用的tar解压命令总结下,当作备忘
- 浅谈 Linux 系统中的 SNMP Trap
- tomcat内存溢出问题
- 28、新消息界面布局与适配器NewMsgAdpter
- 如何锁定 Xcode
- perl 爬取数据<1>
- matlab练习程序(倾斜校正,透视变换)
- Java学习笔记
- 对android四大启动模式的理解
- Android开发优化之——对Bitmap的内存优化
- JAVA Some Simple Class And Method Use.
- 29、下拉刷新组件SwipeLayout
- ICPCCamp 2016 Day 6 - Spb SU and Spb AU Contest(Set intersection-随机)
- update 值从临时表取