How to write a check-in script?

After two days to move bricks, a good programmer is to whole several side jobs. Stop for a few days, 🐦🐦, but few people watch it anyway.


Tonight, my cousin’s classmate’s aunt’s son asked me to help write a script for checking in at a time. I’m just going to document the whole thing.

1

Find the network request


The web site communicates with the server simply by asking for something from the server, or sending something to the server, which is always the request the browser sends to the server, and what the script does is simulate that request.


Debugging tools allow you to view requests sent by the browser and the data received for those requests. By looking at the request content, we can filter out the target request that we want to emulate.


Taking Zhihu as an example, we can see that when we click to view the next page, the browser sends a request for the next page to the back-end server and gets a reply.



We’ll copy it as curl here. If you want to make node.js fetch directly at this stage, you can copy it as Node.js fetch.


2

Use Postman to generate code


I want to use node.js request to create a script, so we can copy to curl, using Postman to generate node.js request code.


Click import in the top right corner of postman, select Paste Raw Text, and paste the curl we copied into it



So you get a get request in postman



Postman allows you to export node.js, Python, PHP, Ruby, etc.



At this point, we have a piece of Node.js code that we can copy into our code file.


3

Let the script execute periodically on Linux/Win


The script is already written, so let’s see if we can run it. In my script main.js, for example, if I use a command


$ node main.jsCopy the code


If it runs, it’s normal, and if you’re writing a Python script, the corresponding command is


$ python main.pyCopy the code


The next step is to let the script run regularly, whether the achievement depends on this step.


Linux:

Linux is relatively easy to operate on the command line. First we open the scheduled task list


$ crontab -eCopy the code


Adds a line to the open scheduled task list


0 1 * * * node The absolute path to your scriptCopy the code



Including 1 0 * * * are used to set the running time, is 1 0 run every day, it is worth noting that to confirm the following your machine’s time zone, if your machine is a standard time zone, don’t forget to minus 8 hours, for example, you want to run the script at 2 o ‘clock midnight, every day should be set to 0 18 * * *.


That’s it for Linux, but what if you don’t have a Linux server? You can go to collect ali cloud students preferential wool9.9 yuan a month is more honest. If you are using an Ubuntu 18.04 image, you need to install Postfix before you set the scheduled task. Otherwise, an error will be reported (cronJob will send you an email if the scheduled script has output. Postfix is an email service).


On debian Linux, you can run the following command to view script run logs:


$ grep CRON /var/log/syslogCopy the code



Windows:

Need to write a BAT script, create a TXT file, write a line in it


node main.jsCopy the code


Save and change the file suffix to.bat

Then set the timing to start. This step diagram is too much, affect the viewing experience, baidu for everyone a tutorial. You can click to view the original article.

The articles


Dry stuff | Can your location information when you punch in be faked?


Improve your web experience with the Oil Monkey script in Chrome