nodejs 爬虫项目大作业

基于第一个爬虫项目,现在大作业要求如下:
在这里插入图片描述
首先要在项目文件的终端中输入 npm install 将安装所有依赖的node modules。
然后再安装的过程中出现了无法安装nodejieba的问题,于是按照助教给的方法!
在这里插入图片描述
我们是要对需要对用户的信息进行保存并且还要使得用户可以有注册和登录的操作,并将用户的账号密码保存在数据库中,新建立两个mysql表用来保存用户的操作日志,具体过程如下:
在这里插入图片描述
在这里插入图片描述
然后是相应的mysql配置文件:
在这里插入图片描述
接下来是要对用户的注册登录进行完善,完全用户可注册登录网站,非注册用户不可登录查看数据,对于登录和注册时的错误也要有适当的提示。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
引入angular.js,这样登陆成功会跳转到news.html页面。
然后是注册页的代码:
同时我们还要实现注册用户和非注册用户对网站访问的区别,在登录页路由中,调用userDAO,然后保存session信息达到记录特定用户操作日志的效果。注册操作和退出登录的实现,注意退出时清除session。UserDAO的代码实现以及session的设置等都如下:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
然后在search.html中写好查询页面代码,然后再news.html中将其引入,来实现查询功能。

<form class="form-horizontal" role="form">
    <div class="row" style="margin-bottom: 10px;">
        <label class="col-lg-2 control-label">标题关键字</label>
        <div class="col-lg-3">
            <input type="text" class="form-control" placeholder="标题关键字" ng-model="$parent.title1">
        </div>
        <div class="col-lg-1">
            <select class="form-control" autocomplete="off" ng-model="$parent.selectTitle">
                <option selected="selected">AND</option>
                <option>OR</option>

            </select>
        </div>
        <div class="col-lg-3">
            <input type="text" class="form-control" placeholder="标题关键字" ng-model="$parent.title2">
        </div>
    </div>



    <div class="row" style="margin-bottom: 10px;">
        <label class="col-lg-2 control-label">内容关键字</label>
        <div class="col-lg-3">
            <input type="text" class="form-control" placeholder="内容关键字" ng-model="$parent.content1">
        </div>
        <div class="col-lg-1">
            <select class="form-control" autocomplete="off" ng-model="$parent.selectContent">
                <option selected="selected">AND</option>
                <option>OR</option>
            </select>
        </div>
        <div class="col-lg-3">
            <input type="text" class="form-control" placeholder="内容关键字" ng-model="$parent.content2">
        </div>
    </div>


    <div class="form-group">
        <div class="col-md-offset-9">
            <button type="submit" class="btn btn-default" ng-click="search()">查询</button>
        </div>
    </div>

</form>

<!--显示查询结果-->
<div ng-show="isisshowresult">

    <table class="table table-striped">
        <thead>
            <tr>
                <td>序号</td>
                <td>标题</td>
                <td>作者</td>
<!--                <td>内容</td>-->
                <td>关键词</td>
                <td>链接</td>
                <td>发布时间</td>
            </tr>

        </thead>
        <tbody>
        <tr ng-repeat="(key, item) in items">
            <td>{
   {
   index+key}}</td>
            <td>{
   {
   item.title}}</td>
            <td>{
   {
   item.author}}</td>
<!--            <td>{
   {
   item.content}}</td>-->
            <td>{
   {
   item.keywords}}</td>
            <td>{
   {
   item.url}}</td>
            <td>{
   {
   item.publish_date}}</td>
        </tr>

        </tbody>
    </table>

    <div class="row">
<!--        <div class="form-group">-->
        <div class="pull-left" style="margin-top: 12px;">
            <button type="submit" class="btn btn-primary" ng-click="searchsortASC()" >发布时间升序</button>
            <button type="submit" class="btn btn-primary" ng-click="searchsortDESC()">发布时间降序</button>
        </div>
<!--        </div>-->
        <div class="pull-right">
            <nav>
                <ul class="pagination">
                    <li>
                        <a ng-click="Previous()" role="button"><span role="button">上一页</span></a>
                    </li>
                    <li ng-repeat="page in pageList" ng-class="{active:isActivePage(page)}" role="button">
                        <a ng-click="selectPage(page)" >{
   {
    page }}<
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码 微信小程序源码-毕业设计期末大作业课程设计源码
要编写一个Node.js爬虫并进行登录,需要遵循以下步骤: 1. 安装Node.js和相关依赖库:可以使用npm来安装request、cheerio、superagent等库,这些库可以帮助你发送HTTP请求和解析HTML。 2. 了解登录机制:在进行登录之前,需要了解你要爬取的网站的登录机制,通常网站会使用cookie和session来管理用户登录状态。你需要在请求头中添加cookie和session信息来模拟用户登录状态。 3. 发送登录请求:使用superagent库来发送POST请求,携带用户名和密码等登录信息,获取cookie和session信息。 4. 保存cookie和session信息:将获取到的cookie和session信息保存下来,在后续的爬虫请求中使用。 5. 发送爬虫请求:使用request库来发送HTTP请求,通过添加cookie和session信息来模拟用户登录状态,获取需要的数据。 以下是一个简单的Node.js爬虫登录示例代码: ```javascript const request = require('request'); const cheerio = require('cheerio'); const superagent = require('superagent'); // 登录信息 const loginInfo = { username: 'your_username', password: 'your_password' }; // 登录请求地址 const loginUrl = 'http://example.com/login'; // 发送登录请求 superagent.post(loginUrl) .send(loginInfo) .end((err, res) => { // 获取cookie和session信息 const cookie = res.header['set-cookie']; const session = res.body.session; // 保存cookie和session信息 const options = { url: 'http://example.com', headers: { 'Cookie': cookie, 'Session': session } }; // 发送爬虫请求 request(options, (error, response, body) => { const $ = cheerio.load(body); // 解析HTML获取需要的数据 const data = $('h1').text(); console.log(data); }); }); ``` 注意:以上示例代码仅供参考,具体实现方式需要根据网站的登录机制和数据获取方式进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值