demand

  1. Get all urls and access times from your object’s Chrome browser history from the previous day and save them in a TXT file
  2. Send this TXT file to the specified email address (your email)
  3. Set up a routine and automate these actions at regular times throughout the day so that you can check email to see what your objects are looking at

Background Where is chrome browsing history on a MAC? How to get the url (URL) and access time? Answer: path: / Users/username/Library/Application/Support/Google/Chrome/Default/History History: SQLite is an SQLite database, which is essentially a file that can be accessed using the DB Browser for SQLite. How do we get the information we need in the urls table: use Python’s built-in SQlite3 library to connect to History and use SQL to get the information we want

  1. How do I send an email with attachments?

    A: Use python’s built-in email and smtplib modules to construct and send emails

  2. How do you automate these processes?

    A: Connect these procedures using a shell script, and then run them periodically using the crontab command

requirements

macOS Sierra

Python3.6

Chrome

The QQ email address for sending emails

Qq mailbox authorization code

SMTP server address: smtp.qq.com

Email address to receive mail

code

  1. get_history.py

  2. send_email.py

  3. start.sh

  4. crontab -e

perform

(1) First we use DB Browser for SQLite to see the data composition of the urls table in History

From the table, we can see that the url and visit time we want are in urls.url and urls.last_visit_time

(2) get_history.py: With this script, we can extract the URL and access time and store it in

In result.txt, the following image is part of the result I got

Send_email. py: With this script, we can send result. TXT as an attachment to the specified email address

(4)./start.sh: In fact, the previous several scripts have completed our task, but execute so many legs each time

Ben, this is too much trouble. We can organize the execution statements of these scripts into a shell script. cp /Users/Marcel/Library/Application\ Support/Google/Chrome/Default/History /Users/Marcel/Desktop/tmp/code/chrome_history/ python /Users/Marcel/Desktop/tmp/code/chrome_history/get_history.py python /Users/Marcel/Desktop/tmp/code/chrome_history/send_mail.py /Users/Marcel/Desktop/tmp/code/chrome_history/result

If we execute./start.sh at the terminal, the system will execute the three statements for us

Note: Since the crontab command requires absolute paths, all paths are absolute paths

(5) crontab: if this command is used, the system will execute it automatically when the computer is turned on and connected to the Internet, and then send the result to your email

Usage: Enter crontab -e in terminal and use vim to enter the following line of code

20 14 * * * /Users/Marcel/Desktop/tmp/code/chrome_history/start.sh
1
Copy the code

Note: the first two numbers are the time you execute this script every day, I set it to 14:20.

The important thing is to write the absolute path again!!

The problem

1. The password in server.login(from_addr, password) function is not the email password, but the authorization code in QQ email

A: QQ mailbox authorization code: what is the authorization code, and how to set it? _QQ mailbox help center

2. When you access The History database, The database is locked!

A: This happens when we open a browser and go to History at the same time. There are two solutions:

Timestamp = last_visit_time = microseconds (last_visit_time = microseconds); Last_visit_time (last_visit_time) = 0:00, 0:00, 0:00, 01/01/1601; Screening data yesterday: now the date of the data and last_visit_time difference less than 1, is the distance from the current time is less than 1 day data 4. Crontab wrong answer: all paths in the crontab to write an absolute path, including the path in py script also should write absolute path! Conclusion It is wrong to use Python to connect to SQLite database and perform SQL operations, use Python to send emails, use shell and crontab to set up automated routine tasks to read other people’s privacy, this article is just a joke by myself, the practical feasibility is not strong, expect to package these into an executable file, Double click can be deployed directly, and can be cross-platform currently this script, only when the computer is open and the Internet, can be automatically executed, so it is not ideal for monitoring other people’s browsing history oh! Finally, I wish you as tenacious as the cover of the grass, as soon as possible on the peak of life

Recently, many friends have sent messages to ask about learning Python. For easy communication, click on blue to join yourselfDiscussion solution resource base