这是一个简单的c++爬虫,效率并不是很高...

 #include<stdio.h>
int s1[],s2[];
void fun(int a, int b)
{
int i,ii;
bool t1,t2,t3,t4;
s1[] = s2[] = s1[] = s2[] = ;
for(i=a; i <= b; i++){
ii = i;
t1 = t2 = t3 = t4 =false;
while(ii != ){
int a = ii %;
if( a == )
{
t1 = true;
}
else if( a == )
{
t2 = true;
}
else if( a == )
{
t3 = true;
}
ii = ii / ;
}
if(t1 && t2 && t3){
s1[i-] = s1[i-] + ;
ii = i;
while(ii != ){
int a = ii % ;
int b = (ii / ) % ;
int c = (ii / ) % ;
if( c > && a == && b == && c ==)
t4 = true;
ii = ii / ;
}
if(t4)
s2[i-] = s2[i-] + ;
else
s2[i-] = s2[i-];
}
else{
s2[i-] = s2[i-];
s1[i-] = s1[i-];
}
}
} int main()
{
int a,b,i=;
fun(,);
while(scanf("%d%d",&a,&b) != EOF){
if(a == )
printf("Case %d:%d %d\n",i,s1[b-]-s1[a-],s2[b-]-s2[a-]);
else
printf("Case %d:%d %d\n",i,s1[b-]-s1[a-],s2[b-]-s2[a-]);
i++;
}
return ;
}
 #include"urlThread.h"
#include<QFile>
#include<QMessageBox>
#include<QTextStream>
#include <QMainWindow>
void urlThread::run()
{
open();
} void urlThread::startThread()
{
start();
} //显示找到的url
void urlThread::open()
{
QString path = "url.txt";
QFile file(path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
// QMessageBox::warning(this,tr("Read File"),
// tr("Cannot open file:\n%1").arg(path));
send("error!cannot open url.txt!");
return;
}
QTextStream in(&file);
while(in.readLine().compare("") != ){
//ui->textBrowser->append(in.readLine());
send(q2s(in.readLine()));
Sleep();
}
file.close();
}
 #include "mainwindow.h"
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.setWindowTitle("小小爬虫");
w.show(); return a.exec();
}
 #include "mainwindow.h"
#include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QObject::connect(ui->start,SIGNAL(released()),this,SLOT(beginGeturl()));
//QObject::connect(ui->display,SIGNAL(released()),this,SLOT(open()));
QObject::connect(ui->display,SIGNAL(released()),&uth,SLOT(startThread()));
QObject::connect(&uth,&urlThread::sendMessage,this,&MainWindow::receiveMessage);
QObject::connect(&crawler,&Crawler::sendMessage,this,&MainWindow::receiveMessage);
} MainWindow::~MainWindow()
{
delete ui;
} void MainWindow::receiveMessage(const QString name)
{
ui->textBrowser->append(name);
ui->textBrowser->moveCursor(QTextCursor::End);
} void MainWindow::open()
{
QString path = "url.txt";
QFile file(path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::warning(this,tr("Read File"),
tr("Cannot open file:\n%1").arg(path));
return;
}
QTextStream in(&file);
while(in.readLine().compare("") != ){
//ui->textBrowser->append(in.readLine());
crawler.send(q2s(in.readLine()));
}
file.close();
} void MainWindow::beginGeturl()
{
//crawler = new Crawler();
string url = "" ,dep, filter = "www";
if(!ui->site->text().isEmpty())
url = q2s(ui->site->text());
crawler.addURL(url);
int depth = ;
if(!ui->depth->text().isEmpty())
{
url = q2s(ui->depth->text());
depth = atoi(url.c_str());
}
if(!ui->filter->text().isEmpty())
filter = q2s(ui->filter->text());
crawler.setJdugeDomain(filter);
crawler.setDepth(depth);
crawler.startThread();
}
 #ifndef CRAWLER_H
#define CRAWLER_H #include<set>
#include<string>
#include<queue>
#include "winsock2.h"
#include <iostream>
#include <fstream>
#include <stdio.h>
#include<time.h>
#include<winsock.h>
#include<QThread> #pragma comment(lib, "ws2_32.lib")
using namespace std; bool ParseURL(const string & url, string & host, string & resource);
bool GetHttpResponse(const string & url, char * &response, int &bytesRead);
QString s2q(const string &s);
string q2s(const QString &s); #define DEFAULT_PAGE_BUF_SIZE 1000000 class Crawler: public QThread
{
Q_OBJECT
private:
queue<string> urlWaiting;
set<string> urlWaitset;
set<string> urlProcessed;
set<string> urlError;
set<string> disallow;
set<string>::iterator it;
int numFindUrl;
time_t starttime, finish;
string filter;
int depth; public:
Crawler(){ filter = "\0";numFindUrl = ;}
~Crawler(){}
void begin();
void setDepth(int depth);
void processURL(string& strUrl);
void addURL(string url);
void log(string entry, int num);
void HTMLParse(string & htmlResponse, const string & host);
bool getRobotx(const string & url, char * &response, int &bytesRead);
void setJdugeDomain(const string domain);
long urlOtherWebsite(string url);
void send(string s)
{
QString qs = s2q(s);
emit sendMessage(qs);
}
signals:
void sendMessage(const QString name); public slots:
bool startThread(); protected:
void run(); };
#endif // CRAWLER_H
 #ifndef MAINWINDOW_H
#define MAINWINDOW_H #include <QMainWindow>
#include<QFile>
#include<QMessageBox>
#include<QTextStream>
#include<QLineEdit>
#include<QDebug>
#include"crawler.h"
#include"urlThread.h" namespace Ui {
class MainWindow;
} class MainWindow : public QMainWindow
{
Q_OBJECT public:
explicit MainWindow(QWidget *parent = );
~MainWindow();
void receiveMessage(const QString name); public slots:
void beginGeturl();
void open(); private:
Ui::MainWindow *ui;
Crawler crawler;
urlThread uth;
}; #endif // MAINWINDOW_H
 #ifndef URLTHREAD_H
#define URLTHREAD_H
#include"crawler.h" class urlThread: public QThread
{
Q_OBJECT
public slots:
void startThread();
void open();
void send(string s)
{
QString qs = s2q(s);
emit sendMessage(qs);
}
signals:
void sendMessage(const QString name);
protected:
void run();
}; #endif // URLTHREAD_H
 <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x></x>
<y></y>
<width></width>
<height></height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x></x>
<y></y>
<width></width>
<height></height>
</rect>
</property>
<property name="text">
<string>初始网址:</string>
</property>
</widget>
<widget class="QLineEdit" name="site">
<property name="geometry">
<rect>
<x></x>
<y></y>
<width></width>
<height></height>
</rect>
</property>
<property name="text">
<string>http://www.scut.edu.cn</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x></x>
<y></y>
<width></width>
<height></height>
</rect>
</property>
<property name="text">
<string>搜索深度:</string>
</property>
</widget>
<widget class="QLineEdit" name="depth">
<property name="geometry">
<rect>
<x></x>
<y></y>
<width></width>
<height></height>
</rect>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x></x>
<y></y>
<width></width>
<height></height>
</rect>
</property>
<property name="text">
<string>过滤字符串:</string>
</property>
</widget>
<widget class="QLineEdit" name="filter">
<property name="geometry">
<rect>
<x></x>
<y></y>
<width></width>
<height></height>
</rect>
</property>
<property name="text">
<string>scut</string>
</property>
</widget>
<widget class="QPushButton" name="start">
<property name="geometry">
<rect>
<x></x>
<y></y>
<width></width>
<height></height>
</rect>
</property>
<property name="text">
<string>开始</string>
</property>
</widget>
<widget class="QPushButton" name="display">
<property name="geometry">
<rect>
<x></x>
<y></y>
<width></width>
<height></height>
</rect>
</property>
<property name="text">
<string>显示url</string>
</property>
</widget>
<widget class="QTextBrowser" name="textBrowser">
<property name="geometry">
<rect>
<x></x>
<y></y>
<width></width>
<height></height>
</rect>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x></x>
<y></y>
<width></width>
<height></height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="" margin=""/>
<resources/>
<connections/>
</ui>

ui文件要自己设计

爬虫还有一些小问题,抓取的url content并不完全,某些地址还有一点小问题...

貌似博客园没有上传附件的地方?还是我没找到?希望得到提示~

c++ 爬虫的更多相关文章

  1. 设计爬虫Hawk背后的故事

    本文写于圣诞节北京下午慵懒的午后.本文偏技术向,不过应该大部分人能看懂. 五年之痒 2016年,能记入个人年终总结的事情没几件,其中一个便是开源了Hawk.我花不少时间优化和推广它,得到的评价还算比较 ...

  2. Scrapy框架爬虫初探——中关村在线手机参数数据爬取

    关于Scrapy如何安装部署的文章已经相当多了,但是网上实战的例子还不是很多,近来正好在学习该爬虫框架,就简单写了个Spider Demo来实践.作为硬件数码控,我选择了经常光顾的中关村在线的手机页面 ...

  3. Python 爬虫模拟登陆知乎

    在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...

  4. scrapy爬虫docker部署

    spider_docker 接我上篇博客,为爬虫引用创建container,包括的模块:scrapy, mongo, celery, rabbitmq,连接https://github.com/Liu ...

  5. scrapy 知乎用户信息爬虫

    zhihu_spider 此项目的功能是爬取知乎用户信息以及人际拓扑关系,爬虫框架使用scrapy,数据存储使用mongo,下载这些数据感觉也没什么用,就当为大家学习scrapy提供一个例子吧.代码地 ...

  6. 120项改进:开源超级爬虫Hawk 2.0 重磅发布!

    沙漠君在历时半年,修改无数bug,更新一票新功能后,在今天隆重推出最新改进的超级爬虫Hawk 2.0! 啥?你不知道Hawk干吗用的? 这是采集数据的挖掘机,网络猎杀的重狙!半年多以前,沙漠君写了一篇 ...

  7. Python爬虫小白入门(四)PhatomJS+Selenium第一篇

    一.前言 在上一篇博文中,我们的爬虫面临着一个问题,在爬取Unsplash网站的时候,由于网站是下拉刷新,并没有分页.所以不能够通过页码获取页面的url来分别发送网络请求.我也尝试了其他方式,比如下拉 ...

  8. Python多线程爬虫爬取电影天堂资源

    最近花些时间学习了一下Python,并写了一个多线程的爬虫程序来获取电影天堂上资源的迅雷下载地址,代码已经上传到GitHub上了,需要的同学可以自行下载.刚开始学习python希望可以获得宝贵的意见. ...

  9. QQ空间动态爬虫

    作者:虚静 链接:https://zhuanlan.zhihu.com/p/24656161 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 先说明几件事: 题目的意 ...

  10. 让你从零开始学会写爬虫的5个教程(Python)

    写爬虫总是非常吸引IT学习者,毕竟光听起来就很酷炫极客,我也知道很多人学完基础知识之后,第一个项目开发就是自己写一个爬虫玩玩. 其实懂了之后,写个爬虫脚本是很简单的,但是对于新手来说却并不是那么容易. ...

随机推荐

  1. 图示-Centos7完整安装

    工作过程中,一些未接触过Centos,或未安装过Centos的同事经常会问,如何安装?这个事说简单真简单,只有操作过一次,第二次就能够熟练的自己动手安装:但说难也难,如果没人带,第一次安装的时候确实不 ...

  2. fork和exec一起使用

    先预览一下工程的目录树: 实现的功能:master进程启动slave进程. 看看Makefile内容: all: master.out slave.out master.out: master.cpp ...

  3. PHP实现单例模式

    <?php /** * [单例模式] * 总结:防止外部new对象:防止子类继承:防止克隆. */ header("Content-type: text/html; charset=u ...

  4. run loop 输入源

    做了一年多的IOS开发,对IOS和Objective-C深层次的了解还十分有限,大多还停留在会用API的级别,这是件挺可悲的事情.想学好一门语言还是需要深层次的了解它,这样才能在使用的时候得心应手,出 ...

  5. 7.进度条(ProgressBar)

    默认为圆形,类似加载的样子,如果想要设置为下载的样式,可以选择它的样式为横向. style="?android:attr/progressBarStyleHorizontal" 顺 ...

  6. WAMP,BITNAMI上建立多个虚拟主机都访问到主站上去了怎么解决?

    新建立了多个虚拟主机,访问的结果都是localhost,只要把localhost也建立成一个虚拟主机所有的虚拟主机访问就正常了.

  7. linux poll 学习

    一.poll介绍 函数原型: #include <poll.h> int poll(struct pollfd *fds, nfds_t nfds, int timeout); struc ...

  8. flash压力测试

    涉及目录: vendor/mediatek/proprietary/bootable/bootloader/preloader/platform/mt6735/src/drivers/inc/dram ...

  9. Android JUnit Test——批量运行测试代码

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ Android测试三要素 写Android测试用例有三要素,一是我们用的“安卓模拟器device” ...

  10. zoj 3557 How Many Sets II

    How Many Sets II Time Limit: 2 Seconds      Memory Limit: 65536 KB Given a set S = {1, 2, ..., n}, n ...