1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241#!/bin/bash
# Facebook Marketplace Scraper - Linux Setup Script
# This script installs all dependencies needed to run the scraper on Linux
set -e # Exit on error
echo "=========================================="
echo "Facebook Marketplace Scraper Setup"
echo "=========================================="
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_success() {
echo -e "${GREEN}โ${NC} $1"
}
print_error() {
echo -e "${RED}โ${NC} $1"
}
print_info() {
echo -e "${YELLOW}โน${NC} $1"
}
# Check if Python 3 is installed
echo "Checking Python installation..."
if command -v python3 &> /dev/null; then
PYTHON_VERSION=$(python3 --version | cut -d' ' -f2)
print_success "Python 3 found: $PYTHON_VERSION"
else
print_error "Python 3 is not installed. Please install Python 3.8 or higher."
echo "On Ubuntu/Debian: sudo apt-get install python3 python3-pip python3-venv"
echo "On CentOS/RHEL: sudo yum install python3 python3-pip"
exit 1
fi
# Check Python version (need 3.8+)
PYTHON_MAJOR=$(python3 -c 'import sys; print(sys.version_info.major)')
PYTHON_MINOR=$(python3 -c 'import sys; print(sys.version_info.minor)')
if [ "$PYTHON_MAJOR" -lt 3 ] || ([ "$PYTHON_MAJOR" -eq 3 ] && [ "$PYTHON_MINOR" -lt 8 ]); then
print_error "Python 3.8 or higher is required. Found: $PYTHON_VERSION"
exit 1
fi
# Check if pip is installed
echo ""
echo "Checking pip installation..."
if command -v pip3 &> /dev/null; then
print_success "pip3 found"
else
print_info "pip3 not found, installing..."
if command -v apt-get &> /dev/null; then
sudo apt-get update
sudo apt-get install -y python3-pip
elif command -v yum &> /dev/null; then
sudo yum install -y python3-pip
elif command -v dnf &> /dev/null; then
sudo dnf install -y python3-pip
else
print_error "Could not find package manager. Please install pip3 manually."
exit 1
fi
fi
# Detect Linux distribution
echo ""
echo "Detecting Linux distribution..."
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
print_info "Detected distribution: $DISTRO"
else
print_info "Could not detect distribution, will try common packages"
DISTRO="unknown"
fi
# Install system dependencies for Playwright
echo ""
echo "Installing system dependencies for Playwright..."
if [ "$DISTRO" = "ubuntu" ] || [ "$DISTRO" = "debian" ]; then
print_info "Installing dependencies for Ubuntu/Debian..."
sudo apt-get update
sudo apt-get install -y \
libnss3 \
libnspr4 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libdbus-1-3 \
libxkbcommon0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libasound2 \
libatspi2.0-0 \
libxshmfence1 \
libxss1 \
ca-certificates \
fonts-liberation \
libappindicator3-1 \
xdg-utils \
wget
print_success "System dependencies installed"
elif [ "$DISTRO" = "centos" ] || [ "$DISTRO" = "rhel" ] || [ "$DISTRO" = "fedora" ]; then
print_info "Installing dependencies for CentOS/RHEL/Fedora..."
if command -v dnf &> /dev/null; then
sudo dnf install -y \
nss \
nspr \
atk \
at-spi2-atk \
cups-libs \
libdrm \
libxkbcommon \
libXcomposite \
libXdamage \
libXfixes \
libXrandr \
mesa-libgbm \
alsa-lib \
at-spi2-core \
libXScrnSaver \
liberation-fonts \
xdg-utils \
wget
else
sudo yum install -y \
nss \
nspr \
atk \
at-spi2-atk \
cups-libs \
libdrm \
libxkbcommon \
libXcomposite \
libXdamage \
libXfixes \
libXrandr \
mesa-libgbm \
alsa-lib \
at-spi2-core \
libXScrnSaver \
liberation-fonts \
xdg-utils \
wget
fi
print_success "System dependencies installed"
else
print_info "Unknown distribution. Playwright will attempt to install dependencies automatically."
print_info "If you encounter issues, you may need to install browser dependencies manually."
fi
# Create virtual environment (optional but recommended)
echo ""
read -p "Create a Python virtual environment? (recommended) [y/N]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
print_info "Creating virtual environment..."
python3 -m venv venv
print_success "Virtual environment created"
print_info "To activate: source venv/bin/activate"
ACTIVATE_VENV=true
else
ACTIVATE_VENV=false
fi
# Install Python dependencies
echo ""
echo "Installing Python dependencies..."
if [ "$ACTIVATE_VENV" = true ]; then
source venv/bin/activate
print_info "Virtual environment activated"
fi
pip3 install --upgrade pip
print_success "pip upgraded"
if [ -f requirements.txt ]; then
print_info "Installing packages from requirements.txt..."
pip3 install -r requirements.txt
print_success "Python dependencies installed"
else
print_error "requirements.txt not found!"
exit 1
fi
# Install Playwright browsers
echo ""
echo "Installing Playwright browsers..."
python3 -m playwright install chromium
print_success "Chromium browser installed"
# Install Playwright system dependencies
echo ""
echo "Installing Playwright system dependencies..."
python3 -m playwright install-deps chromium
print_success "Playwright system dependencies installed"
# Create data directory if it doesn't exist
echo ""
echo "Setting up directories..."
mkdir -p data/cache
print_success "Data directories created"
# Set permissions
chmod -R 755 data/
print_success "Directory permissions set"
# Summary
echo ""
echo "=========================================="
echo "Setup Complete!"
echo "=========================================="
echo ""
print_success "All dependencies installed successfully!"
echo ""
echo "Next steps:"
echo "1. If you created a virtual environment, activate it:"
echo " ${GREEN}source venv/bin/activate${NC}"
echo ""
echo "2. Set up your Facebook credentials (optional, can use cookies instead):"
echo " ${GREEN}export FB_EMAIL='your_email@example.com'${NC}"
echo " ${GREEN}export FB_PASSWORD='your_password'${NC}"
echo ""
echo "3. Run the scraper:"
echo " ${GREEN}python3 main.py 'your search query' --headless${NC}"
echo ""
echo "Note: Use ${GREEN}--headless${NC} flag when running over SSH or without a display."
echo ""