Pickles Script Untested With Instructions
Pickles Script Untested With Instructions
1. A Python scraper that downloads and parses car listings from the Pickles Salvage
website,
3. Instructions on how to set up the system and run it daily at 1 am AEST (or any chosen
time).
1. Database Setup
Create a new MySQL database (e.g., car_listings) and a table (listings) with the
following schema:
Unset
CREATE DATABASE car_listings;
USE car_listings;
Note: If you want to call your table something else or add indexing, feel free to
modify the schema as needed.
2. Python Scraper
2.1 Requirements
Python Dependencies:
● requests
● beautifulsoup4
● pymysql
Unset
pip install requests beautifulsoup4 pymysql
Python
import os
import requests
from bs4 import BeautifulSoup
import pymysql
from datetime import datetime
PHOTO_DIR = "car_photos"
os.makedirs(PHOTO_DIR, exist_ok=True)
def save_to_db(data):
with db.cursor() as cursor:
sql = """
INSERT INTO listings (
year, brand, model, vehicle_type, color, wovr_status,
incident_type,
compliance_date, transmission, drive_type,
engine_capacity, fuel,
cylinders, registration, doors, vin, damage_details,
views, watchers,
location, start_date, stock, price,
total_times_listed, added_date, url
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
ON DUPLICATE KEY UPDATE added_date = VALUES(added_date)
"""
cursor.execute(sql, (
data["year"], data["brand"], data["model"],
data["vehicle_type"], data["color"],
data["wovr_status"], data["incident_type"],
data["compliance_date"], data["transmission"],
data["drive_type"], data["engine_capacity"],
data["fuel"], data["cylinders"],
data["registration"], data["doors"], data["vin"],
data["damage_details"],
data["views"], data["watchers"], data["location"],
data["start_date"],
data["stock"], data["price"],
data["total_times_listed"], data["added_date"],
data["url"]
))
db.commit()
def scrape_details(listing_url):
response = requests.get(listing_url)
soup = BeautifulSoup(response.text, "html.parser")
data = {}
data["url"] = listing_url
data["added_date"] = datetime.now().strftime("%Y-%m-%d
%H:%M:%S")
data["price"] = None
data["total_times_listed"] = None
data["year"] = year
data["brand"] = brand
data["model"] = model
return data
def scrape_pickles():
search_url =
"https://www.pickles.com.au/used/search/lob/salvage?search=m2%2Cm
3%2Cm4&page=1"
response = requests.get(search_url)
soup = BeautifulSoup(response.text, "html.parser")
if __name__ == "__main__":
scrape_pickles()
Unset
python scrape_pickles.py
2.
This will connect to your database, scrape the listings, and populate the listings
table.
○ Convert 1 AM AEST to UTC time (AEST is typically +10 hours from UTC, or +11
if daylight savings applies).
○ Create a cron job (if on Linux/Unix). Example for 1 AM AEST = 15:00 UTC:
Unset
crontab -e
○ Then add:
Unset
0 15 * * * /usr/bin/python /path/to/scrape_pickles.py
○ Replace /usr/bin/python with the path to your Python executable and
/path/to/ with the location of the script.
4. On Windows, use Task Scheduler:
Unset
<?php
$host = "localhost";
$user = "your_user";
$password = "your_password";
$database = "car_listings";
$search = isset($_GET['search']) ?
$conn->real_escape_string($_GET['search']) : '';
$order_by = isset($_GET['order_by']) ?
$conn->real_escape_string($_GET['order_by']) : 'brand';
$order_dir = (isset($_GET['order_dir']) && $_GET['order_dir'] ===
'desc') ? 'DESC' : 'ASC';
$sql = "
SELECT *
FROM listings
WHERE
brand LIKE '%$search%' OR
model LIKE '%$search%' OR
vehicle_type LIKE '%$search%' OR
color LIKE '%$search%' OR
CAST(price AS CHAR) LIKE '%$search%' OR
CAST(year AS CHAR) LIKE '%$search%'
ORDER BY $order_by $order_dir
";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Car Listings</title>
<style>
table {
border-collapse: collapse;
width: 90%;
margin: 20px auto;
}
th, td {
border: 1px solid #eaeaea;
padding: 10px;
text-align: left;
}
th {
background: #f2f2f2;
}
th a {
text-decoration: none;
color: #000;
}
.search-form {
text-align: center;
margin: 20px;
}
.search-form input[type="text"] {
padding: 5px;
}
.search-form button {
padding: 5px 10px;
}
h1 {
text-align: center;
}
</style>
</head>
<body>
<h1>Car Listings</h1>
<div class="search-form">
<form method="get">
<input type="text" name="search" placeholder="Search..."
value="<?php echo htmlspecialchars($search); ?>">
<button type="submit">Search</button>
</form>
</div>
<table>
<thead>
<tr>
<th>
<a href="?order_by=year&order_dir=<?php echo
($order_by === 'year' && $order_dir === 'ASC') ? 'desc' : 'asc';
?>">
Year
</a>
</th>
<th>
<a href="?order_by=brand&order_dir=<?php echo
($order_by === 'brand' && $order_dir === 'ASC') ? 'desc' : 'asc';
?>">
Brand
</a>
</th>
<th>
<a href="?order_by=model&order_dir=<?php echo
($order_by === 'model' && $order_dir === 'ASC') ? 'desc' : 'asc';
?>">
Model
</a>
</th>
<th>
<a href="?order_by=vehicle_type&order_dir=<?php
echo ($order_by === 'vehicle_type' && $order_dir === 'ASC') ?
'desc' : 'asc'; ?>">
Type
</a>
</th>
<th>
<a href="?order_by=color&order_dir=<?php echo
($order_by === 'color' && $order_dir === 'ASC') ? 'desc' : 'asc';
?>">
Color
</a>
</th>
<th>
<a href="?order_by=price&order_dir=<?php echo
($order_by === 'price' && $order_dir === 'ASC') ? 'desc' : 'asc';
?>">
Price
</a>
</th>
</tr>
</thead>
<tbody>
<?php if ($result && $result->num_rows > 0): ?>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo htmlspecialchars($row['year']);
?></td>
<td><?php echo htmlspecialchars($row['brand']);
?></td>
<td><?php echo htmlspecialchars($row['model']);
?></td>
<td><?php echo
htmlspecialchars($row['vehicle_type']); ?></td>
<td><?php echo htmlspecialchars($row['color']);
?></td>
<td><?php echo htmlspecialchars($row['price']);
?></td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr><td colspan="6" style="text-align:center;">No results
found</td></tr>
<?php endif; ?>
</tbody>
</table>
</body>
</html>
<?php
$conn->close();
?>
Unset
/home/user/scraper/scrape_pickles.py
4.
Update scrape_pickles.py with:
Unset
python scrape_pickles.py
6.
Check the listings table in your MySQL database to confirm data has been inserted.
Also, verify a car_photos/ folder was created and listing images were saved inside
subfolders named by their stock field.
○ Linux/Unix:
Unset
crontab -e
○ Windows: Use Task Scheduler to run the same command daily at your chosen
time.
8. Set up the PHP interface (optional):
○ Copy the index.php file into a directory served by your web server (e.g.,
Apache, Nginx).
○ Update the $host, $user, $password, $database variables to match your
MySQL setup.
○ Navigate to the PHP page (e.g., http://yourserver.com/index.php) to
view, search, and sort the listings.
5. Summary
You now have:
● A Python script to scrape data, store it in a MySQL database, and download listing
photos.
● A PHP interface to search and sort the scraped records.
Simply maintain or adjust scheduling as needed, ensure your database credentials are correct,
and your developer should be able to continue from this foundation.
Good luck testing and running your new scraping + search system!