Perl6 必应抓取(1):测试版代码
2024-08-26 02:36:53
一个相当丑漏的代码, 以后有时间再优化了。
默认所有查找都是15页, 如果结果没有15页这么多估计会有重复。速度还是很快的。
sub MAIN() {
my $fp = open 'bin_result.txt', :w;
my $number = ;
print 'String:';
my $string = get;
$string = do given $string {S:g/\s/+/};
use HTTP::UserAgent;
my $url = 'http://cn.bing.com/search?q=';
my $ua = HTTP::UserAgent.new;
my $check = rx/'<'cite'>'(.*?)'</cite>'/;#要查的内容
my @number = '';
@number.append(..$number);
my $page='';
my $html;
my $target = $url~$string~'&first=20&FROM=FERE'~$page;
$html = $ua.get($target).content;
loop {
say '===============> '~$target;
$html ~~ $check;
$html = $/.postmatch;
#$0 = do given ~$0 {S:g/'<strong>'//;}
if not $ {
#当是null时, 说明这一页已全部提取, 构造下一页
$page = Int($page);
my $page_next = $string~'&first='~$page~'0&FROM=FERE'~$page;
$target = $url~$page_next;
$html = $ua.get($target).content;
$page++;
#/search?q=123&first=10&FORM=PERE
#/search?q=123&first=20&FORM=PERE1
#/search?q=123&first=30&FORM=PERE2
#/search?q=123&first=30&FORM=PERE2
#last;
$html ~~ $check;
$html = $/.postmatch;
if ($page > $number) {last;}
}
my $ok_check = $.Str;
my $result = $ok_check;
$result = do given $result {S:g/'<strong>'//;}
$result = do given $result {S:g/'</strong>'//;}
say $result;
$fp.say($result); }
#$fp.print($html);
}
下次代码优化:
总结一下必应的规律, 如下:
http://cn.bing.com/search?q=&first=&FORM=PERE
http://cn.bing.com/search?q=&first=&FORM=PERE
http://cn.bing.com/search?q=&first=&FORM=PERE1
http://cn.bing.com/search?q=&first=&FORM=PERE2
http://cn.bing.com/search?q=&first=&FORM=PERE3
http://cn.bing.com/search?q=&first=&FORM=PERE4
http://cn.bing.com/search?q=&first=&FORM=PERE4
http://cn.bing.com/search?q=&first=&FORM=PERE4
http://cn.bing.com/search?q=&first=&FORM=PERE4
http://cn.bing.com/search?q=&first=&FORM=PERE4
在页面上测试, 参数只虽两个即可:
q=查询字符串&first=起始帐号
最新文章
- [转]六款值得推荐的android(安卓)开源框架简介
- 【转】js onclick用法:跳转到指定URL
- js- 千分位分割
- (转)CentOS5.5 下搭建 PHP 环境(最佳的LAMP环境)
- 【POJ2761】【区间第k大】Feed the dogs(吐槽)
- php 添加 redis 扩展模块
- nyoj 43 24 Point game(dfs暴力)
- HDU1963 &;&; POJ2063:Investment(完全背包)
- Python终端输出打印彩色字体的方法
- 洛谷 [P2756] 飞行员配对方案问题
- 07_Linux目录文件操作命令4解压缩,文件查找_我的Linux之路
- elementUi的时间选择器在IE浏览器的赋值问题--前端
- App功能测试
- servlet简单介绍
- Linux内核启动流程分析(二)【转】
- Go语言类型转换库【github.com/demdxx/gocast】的用法
- 读取 classes下的配置文件
- PHP将富文本内容去除各类样式图片等只保留txt文本内容(作用于SEO的description)
- 在CentOS7上部署Kubernetes集群
- Springboot时间参数格式化
热门文章
- pyspark在windows中的安装
- 关于ADO一个容易被忽视的问题!UpdateBatch [问题点数:0分]
- 大家好,请问在DELPHI中#13和#10是表示什么含义的?
- jenkins配置slave节点 构建项目并执行操作
- luogu 1712 区间(线段树+尺取法)
- 待续--mysql中key 、primary key 、unique key 与index区别
- python中括号的使用
- bzoj2314: 士兵的放置(树形DP)
- 3.6 scikit-learn:Python中的机器学习
- Java中关于Arrays.asList方法的深入学习与理解