Graphic verification plug-in, baidu editor expansion function, nodejs message mechanism and chat room, python do crawler

Time:2021-4-18

Graphics verification plug in

Online to find a lot of graphics verification plug-ins, more recommended verify.js

$('#mpanel4').slideVerify({
            type: 2,
            vOffset: 5,
            vSpace: 5,
            imgName: ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg'],
            imgSize: {
                width: '400px',
                height: '200px',
            },
            blockSize: {
                width: '40px',
                height: '40px',
            },
            barSize: {
                width: '400px',
                height: '40px',
            },
            ready: function () {},
            success: function () {
                $(". Verify left bar. Verify MSG"). HTML ('success');
                $(".verify-left-bar .verify-msg").css('color','#5cb85c');
            },
            error: function () {}
        });

Baidu editor development function

In the red box is the custom function

After the introduction of Baidu editor

  ueditor.all.js 

   

//To add buttons to the toolbar, the following are unified button trigger commands, so they are written together
    Var btncmds = ['translation '-- this is your new function','undo ','redo','formatmatch ',
        'bold', 'italic', 'underline', 'fontborder', 'touppercase', 'tolowercase',
        'strikethrough', 'subscript', 'superscript', 'source', 'indent', 'outdent',
        'blockquote', 'pasteplain', 'pagebreak',
        'selectall', 'print','horizontal', 'removeformat', 'time', 'date', 'unlink',
        'insertparagraphbeforetable', 'insertrow', 'insertcol', 'mergeright', 'mergedown', 'deleterow',
        'deletecol', 'splittorows', 'splittocols', 'splittocells', 'mergecells', 'deletetable', 'drafts'];

ueditor.config.js

, tools: ['translation -- keep the same name as above ',' | ', 
            'fullscreen', 'source', '|', 'undo', 'redo', '|',
            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
            'directionalityltr', 'directionalityrtl', 'indent', '|',
            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
            'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
            'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
            'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
            'print', 'preview', 'searchreplace', 'drafts', 'help'
        ]]
        //When the mouse is placed on the toolbar, the display of the tool tip will be left blank to support automatic multi language configuration. Otherwise, the configuration value will prevail
        //,labelMap:{
        //    'anchor':'', 'undo':''
        //}
                           , labelMap: {
            Translation: Tips for putting the mouse up
        }

Add a command before initializing the editor

UE.commands['translation'] = {

        execCommand: function () {
            var translation =  UE.getEditor ( this.key ); // rich text
              Event triggered after clicking
        },
        queryCommandState: function () {

        }
    };


    var ue = UE.getEditor('editor');

Effect, I add Baidu editor translation function

Nodejs chat room

Nodejs can run on the server and serve as JS server. Keep a long connection with the client nodejs. Business can do timely communication.

   

quote socket.io.js

Server code:

  

var httpd = require('http').createServer(handler);
var io = require('socket.io').listen(httpd);
var fs = require('fs');

Reference three key resources

  

httpd.listen(3000);

Monitor port 3000, generally 8077..

 

function handler(req, res) {
  fs.readFile(__dirname + '/index.html',
    function(err, data) {
      if (err) {
       res.writeHead(500);
       return res.end('Error loading index.html');
      }

      res.writeHead(200);
      res.end(data);
    }
  );
}

Create HTTP link

io.sockets.on('connection', function (socket) {
  socket.on('clientMessage', function(content) {
    socket.emit('serverMessage', 'You said: ' + content);
    var username = null;

    if (socket.username) {
        username = socket.username;
    }
      socket.broadcast.emit('serverMessage', username + ' said: ' + 
        content);
  });

  socket.on('login', function(username) {
    socket.username = username;
    socket.emit('serverMessage', 'Currently logged in as ' + username);
    socket.broadcast.emit('serverMessage', 'User ' + username +
      ' logged in');   
  });

  socket.emit('login');

});

The above is the main code of the corresponding event of nodejs server

var messagesElement = document.getElementById('messages');
        var lastMessageElement = null;
        var id = 1;
        function addMessage(message) {
            var newMessageElement = document.createElement('div');
            var newMessageText = document.createTextNode(message);

            newMessageElement.appendChild(newMessageText);
            messagesElement.insertBefore(newMessageElement,
                lastMessageElement);
            lastMessageElement = newMessageElement;
        }

        var socket = io.connect('http://localhost:3000');
        socket.on('serverMessage', function (content,id) {
            addMessage(content+id );
        });

        socket.on('login', function () {
            var username = prompt('What username would you like to use?');
            socket.emit('login', username);
        });

        var inputElement = document.getElementById('input');

        inputElement.onkeydown = function (keyboardEvent) {
            if (keyboardEvent.keyCode === 13) {
                socket.emit('clientMessage', inputElement.value,'11');
                inputElement.value = '';
                return false;
            } else {
                return true;
            }
        };

The above is the main body code of the corresponding event of the client

Next, let’s talk about the message mechanism

Client var socket= io.connect (‘ http://localhost :3000’);

Server io.sockets.on (‘connection’, function (socket) {

 } 

As long as 500 is not reported, the connection is normal. At this time, the client can actively push messages to the server, and the server can also push messages like the client.

socket.on('login', function (content) {

        socket.emit ('servermessage ','unilateral reply to non broadcast' + content));

        socket.broadcast.emit ('servermessage ','reply to broadcast all' + content)
    })
    socket.emit('login');

The server defines the user login and initiates the login request after the connection is successful

  socket.on('login', function () {
            var username = prompt('What username would you like to use?');
            socket.emit('login', username);
        });

Client response server login incoming login user name

The client machine (not all client machines) that the server unilaterally responds to the request with ﹣ servermessage, and broadcast broadcasts all the machines except the requesting client machine

The client responds to the server “servermessage”

 socket.on('serverMessage', function (content,id) {
            addMessage(content+id );
        });

The message is displayed in HTML, and the server-side active push message mechanism is completed

  inputElement.onkeydown = function (keyboardEvent) {
            if (keyboardEvent.keyCode === 13) {
                socket.emit('clientMessage', inputElement.value,'11');

The client text box writes a message and presses enter to respond to the clientmessage

socket.on('clientMessage', function (content,id) {
       socket.emit ('servermessage ','unilateral reply to non broadcast' + content, ID));

        socket.broadcast.emit ('servermessage ','reply to broadcast all' + content)

    })

The server responds to the clientmessage, and uses the servermessage to request the client IP, and the broadcast to respond to other client IP

 

 

 

Python as a web crawler

options = webdriver.FirefoxOptions () / / using the Firefox emulator as a crawler, you can send and track mouse click page turning and other events
options.add_ Argument (‘– headless’) / / windowless mode
driver = webdriver.Firefox(options=options)
driver.get (” http://registers.centralbank.ie/FirmRegisterDataPage.aspx?firmReferenceNumber=C53877&register=32 “) / / directory address
html = etree.HTML ( driver.page_ Source) / / # analyze the HTML and return to the DOM root node

     

spanList= html.xpath ("//div[@id='ctl00_ cphRegistersMasterPage_ C1wrptfirmregisterdata '] // span ") // you can also use a similar XPath to get the specified node
while index

You can also loop through each element body to get the title of each element. For example, if you find the text of span as: name, the value of the next span is the element to be crawled

Recommended Today

Rust Study RoadMap

background In recent months, I began to learn rust, and began to write some code with rust. Now, I don’t have a deep understanding of rust, but it’s OK to write some code everyday, and I can learn the next step as needed. In the process of learning, the author also read a lot of […]