Perl6 必应抓取(1):测试版代码
一个相当丑漏的代码, 以后有时间再优化了。
默认所有查找都是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=起始帐号



Perl6 必应抓取(1):测试版代码的更多相关文章
- Perl6 必应抓取(2):最终版
use HTTP::UserAgent; use URI::Encode; Firefox/52.0>); my $bing_url = 'http://cn.bing.com/search?q ...
- HttpClient 4.x 执行网站登录并抓取网页的代码
HttpClient 4.x 的 API 变化还是很大,这段代码可用来执行登录过程,并抓取网页. HttpClient API 文档(4.0.x), HttpCore API 文档(4.1) pack ...
- php中抓取网页内容的代码
方法一: 使用file_get_contents方法实现 $url = "http://news.sina.com.cn/c/nd/2016-10-23/doc-ifxwztru695114 ...
- xheditor编辑器上传截图图片抓取远程图片代码
xheditor是一款很不错的开源编辑器,用起来很方便也很强大. 分享一个xheditor直接上传截图的问题解决方法. 第一步.设置参数 localUrlTest:/^https?:\/\/[^\/] ...
- python网页抓取练手代码
from urllib import request import html.parser class zhuaqu(html.parser.HTMLParser): blogHtml = " ...
- Python网络编程_抓取百度首页代码(注释详细)
1 #coding=utf-8 2 #网络编程 3 4 #客户端建立socket套接字 5 #引入socket模块 6 import socket 7 #实例化一个套接字,2个参数分别是: IPV4. ...
- 抓取网站数据不再是难事了,Fizzler(So Easy)全能搞定
首先从标题说起,为啥说抓取网站数据不再难(其实抓取网站数据有一定难度),SO EASY!!!使用Fizzler全搞定,我相信大多数人或公司应该都有抓取别人网站数据的经历,比如说我们博客园每次发表完文章 ...
- PHP的cURL库:抓取网页,POST数据及其他,HTTP认证 抓取数据
From : http://developer.51cto.com/art/200904/121739.htm 下面是一个小例程: ﹤?php// 初始化一个 cURL 对象$curl = curl_ ...
- php中封装的curl函数(抓取数据)
介绍一个封闭好的函数,封闭了curl函数的常用步骤,方便抓取数据. 代码如下: <?php /** * 封闭好的 curl函数 * 用途:抓取数据 * edit by www.jbxue.com ...
随机推荐
- 第146天:移动H5前端性能优化
移动H5前端性能优化 一.概述 1. PC优化手段在Mobile侧同样适用 2. 在Mobile侧我们提出三秒种渲染完成首屏指标 3. 基于第二点,首屏加载3秒完成或使用Loading 4. 基于联通 ...
- 【.Net】从字符串数组中寻找数字的元素
那是写一个类别来处理数字元素并收集起来. 开发程序,解决方法不是唯一的.相同的功能实现,方法不止一个. 参考下面代码: class Ak { private string[] _stringArray ...
- Struts访问序号的设置
- 【JavaScript&jQuery】$.ajax()
$(function(){ $('#send').click(function(){ $.ajax({ type: "GET", url: "test.json" ...
- 二分图匹配模板(dfs+bfs)
dfs版: bool dfs(int u) { for(int i = head[u]; ~i; i = e[i].next) { int v = e[i].v; if(!vis[v]) { vis[ ...
- Qt 事件处理机制
Qt 事件处理机制 因为这篇文章写得特别好,将Qt的事件处理机制能够阐述的清晰有条理,并且便于学习.于是就装载过来了(本文做了排版,并删减了一些冗余的东西,希望原主勿怪),以供学习之用. 简介 在Qt ...
- TCP(Transmission Control Protocol)学习笔记
一.TCP(Transmission Control Protocol)原理介绍(参考维基百科) TCP连接包括三种状态:连接建立.数据传送和连接终止. TCP用三路握手(three-way hand ...
- 【刷题】BZOJ 1036 [ZJOI2008]树的统计Count
Description 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w.我们将以下面的形式来要求你对这棵树完成 一些操作: I. CHANGE u t : 把结点u的权值改为t II. ...
- [HNOI2014]江南乐 博弈论
题面 题面 题解 首先我们知道一个关于除法的重要性质:对于一个固定的\(i\),表达式\(\frac{i}{m}\)的取值只有根号个. 因此我们考虑如何优化SG函数的求解. 观察到在取值相同的同一段中 ...
- 【JavaScript】BOM
一.前言 接着前一章的内容,继续Js的学习. 二.内容 window对象 //确定窗口位置 var leftPos = (typeof window.screenLeft == &quo ...