This was my StackExchange answer
https://apple.stackexchange.com/que...sites-accessed-in-safari-on-mac/449046#449046
Safari's history (
all the history) is in the database ~/Library/Safari/history.db.
For safety, duplicate this database, so you have ~/Library/Safari/history copy.db.
To explore the database I use
SQLPro for SQLite which you can get from the Mac App Store. Use this or any similar app.
Open the database with SQLPro for SQLite.
The first thing you should see (in the left hand pane) is a list of the tables in the database.
Now select Query from the tool bar and enter this query:
Code:
select datetime(v.visit_time + 978307200, 'unixepoch', 'localtime') as date, i.domain_expansion, i.url
from history_items i left join history_visits v on i.id = v.history_item
order by i.id desc
limit 100;
This will combine data from two tables to give you a list of the most recent 100 of your history. The only tricky bit is the conversion of the date to make it readable.
After entering the query and clicking on the green arrow (Execute Query) you should get results in the lower pane similar to those in the screenshot.
When you are happy with the result, increase the limit to show more (or all) of your history - it may well be 100,000 of more.
Use the 'rectangle with arrow' at top left of results choosing 'Export export results set as' and 'CSV...'. Save the file which can then be used in Excel, Numbers (rather slow) or a text editor.
Disclaimer: The query was modified from one I found on the web.