File size: 26,144 Bytes
b36163c cea95e3 b36163c cea95e3 b36163c b37cd5f 318784c b37cd5f b36163c b37cd5f b36163c 9e0ec62 b36163c 9e0ec62 b36163c 74310ee b36163c 78a50fb b36163c 78a50fb b36163c 60f4ac5 b36163c 60f4ac5 b36163c 9d307f4 b36163c cea95e3 9d307f4 7cb5a5f 54b396c 4bc87d2 54b396c 4bc87d2 54b396c e7fbfe0 54b396c b36163c bbd8d94 887edfb 74310ee 887edfb 74310ee 887edfb f153620 887edfb d05ad6e bbd8d94 887edfb bbd8d94 887edfb bbd8d94 5056b03 efe1ece 78a50fb efe1ece 78a50fb efe1ece 78a50fb efe1ece 78a50fb efe1ece 11d720f efe1ece 78a50fb efe1ece 78a50fb efe1ece 78a50fb efe1ece 78a50fb 11d720f dbee6ba efe1ece 78a50fb efe1ece 78a50fb efe1ece 78a50fb efe1ece 78a50fb efe1ece 78a50fb efe1ece bbd8d94 887edfb bbd8d94 887edfb 58846e6 74310ee 58846e6 74310ee 58846e6 887edfb 74310ee 887edfb 74310ee 887edfb bbd8d94 74310ee bbd8d94 74310ee bbd8d94 74310ee bbd8d94 5056b03 f153620 efe1ece f153620 efe1ece bbd8d94 5056b03 159cee8 5056b03 8ded969 5056b03 8ded969 5056b03 8ded969 5056b03 8ded969 5056b03 b36163c 20c59cd b36163c cea95e3 b36163c |
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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
from flask import Flask, request, Response
import requests
import logging
from urllib.parse import urljoin
from urllib.parse import quote
from bs4 import BeautifulSoup
import re
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
app = Flask(__name__)
# Target URL base
TARGET_BASE_URL = "https://superetka.com"
@app.route('/proxy_image')
def proxy_image():
from urllib.parse import unquote
image_url = unquote(request.args.get('url'))
if not image_url:
return 'No URL provided', 400
try:
# Get headers from the incoming request
headers = {key: value for key, value in request.headers if key.lower() != 'host'}
headers['Referer'] = TARGET_BASE_URL
headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36'
# Forward the request to get the image
resp = requests.get(
image_url,
headers=headers,
cookies=request.cookies,
timeout=30,
allow_redirects=True
)
# Check response status
if resp.status_code != 200:
logger.error(f"Error response from target: {resp.status_code}")
return f"Error: {resp.status_code}", resp.status_code
return Response(resp.content, mimetype=resp.headers.get('Content-Type', 'image/jpeg'))
except Exception as e:
logger.error(f"Error proxying image: {str(e)}")
return str(e), 500
@app.route('/', defaults={'path': ''}, methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
@app.route('/<path:path>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
def proxy(path):
# Construct target URL with path and query parameters
if path and path.strip():
# If path is provided, use it
url = f"{TARGET_BASE_URL}/{path}"
else:
# Default to wap.php if no path is provided
url = f"{TARGET_BASE_URL}/etka/wap.php"
# If there are query parameters, append them to the URL
if request.query_string:
url = f"{url}?{request.query_string.decode('utf-8')}"
# Log the constructed URL
logger.info(f"Constructed URL: {url}")
# Log the request
logger.info(f"Received request: {request.method} {request.url}")
logger.info(f"Forwarding to: {url}")
# Get headers from the incoming request
headers = {key: value for key, value in request.headers if key.lower() != 'host'}
try:
# Forward the request to the target server
# Don't pass params separately as they're already in the URL
resp = requests.request(
method=request.method,
url=url,
headers=headers,
data=request.get_data(),
cookies=request.cookies,
allow_redirects=False,
timeout=30
)
# Log the response
logger.info(f"Received response from target: {resp.status_code}")
# Check if response is HTML and filter content if needed
content_type = resp.headers.get('Content-Type', '')
if 'text/html' in content_type:
# Parse HTML content
html_content = resp.content.decode('utf-8', errors='ignore')
soup = BeautifulSoup(html_content, 'html.parser')
# Filter out "Полная версия ETKA"
for element in soup.find_all(string=re.compile('Полная версия ETKA')):
# Replace the text with empty string
element.replace_with('')
# Filter out README content
for element in soup.find_all(string=re.compile('README', re.IGNORECASE)):
element.replace_with('')
# Redirect part number links to Google search
# Look for links that contain part numbers (typically in the second column of the table)
part_number_links = soup.select('td:nth-child(2) a')
for link in part_number_links:
# Get the part number from the link text
part_number = link.text.strip()
# Check if it matches a part number pattern (alphanumeric with possible spaces)
if re.match(r'^[A-Z0-9 ]+$', part_number):
# Create a Google search URL for this part number with avto.pro
google_search_url = f"https://www.google.com/search?q={part_number} avto.pro"
# Update the link's href attribute and add target="_blank" to open in new tab
link['href'] = google_search_url
link['target'] = '_blank'
# Update image sources to use our proxy
for img in soup.find_all('img'):
img_src = img['src']
if not img_src.startswith('http'):
img_src = urljoin(TARGET_BASE_URL, img_src)
proxy_url = f"/proxy_image?url={quote(img_src)}"
img['src'] = proxy_url
img['style'] = 'max-width: 100%; height: auto; border: 1px solid #ddd; border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin: 10px 0;'
# Add "Open Original Image" button next to each image
button = soup.new_tag('a')
button['href'] = proxy_url
button['target'] = '_blank'
button['class'] = 'open-image-btn'
button.string = 'Открыть оригинал изображения'
button['style'] = 'display: inline-block; margin: 10px; padding: 8px 15px; background-color: #4a90e2; border: none; border-radius: 4px; text-decoration: none; color: white; font-weight: 500; transition: all 0.3s ease; box-shadow: 0 2px 4px rgba(0,0,0,0.1);'
img.insert_after(button)
# Add modal container for fullscreen image view
modal_div = soup.new_tag('div')
modal_div['id'] = 'imageModal'
modal_div['class'] = 'modal'
modal_div['style'] = 'display: none;'
modal_img = soup.new_tag('img')
modal_img['id'] = 'modalImage'
modal_img['src'] = ''
modal_img['alt'] = 'Fullscreen Image'
close_btn = soup.new_tag('span')
close_btn['class'] = 'close'
close_btn.string = '×'
modal_div.append(close_btn)
modal_div.append(modal_img)
if soup.body:
soup.body.append(modal_div)
else:
body_tag = soup.new_tag('body')
body_tag.append(modal_div)
if soup.html:
soup.html.append(body_tag)
else:
html_tag = soup.new_tag('html')
html_tag.append(body_tag)
soup.append(html_tag)
# Add JavaScript for modal functionality
script_tag = soup.new_tag('script')
script_tag.string = '''
document.addEventListener('DOMContentLoaded', function() {
var modal = document.getElementById('imageModal');
var modalImg = document.getElementById('modalImage');
var closeBtn = document.getElementsByClassName('close')[0];
var scale = 1;
var isDragging = false;
var startX, startY, translateX = 0, translateY = 0;
// Add zoom controls
var zoomControls = document.createElement('div');
zoomControls.className = 'zoom-controls';
zoomControls.innerHTML = `
<button class="zoom-btn" onclick="changeZoom(0.1)">+</button>
<button class="zoom-btn" onclick="changeZoom(-0.1)">-</button>
<button class="zoom-btn" onclick="resetZoom()">Reset</button>
`;
modal.appendChild(zoomControls);
// Zoom functions
window.changeZoom = function(delta) {
scale = Math.min(Math.max(scale + delta, 0.5), 3);
applyTransform();
};
window.resetZoom = function() {
scale = 1;
translateX = 0;
translateY = 0;
applyTransform();
};
function applyTransform() {
modalImg.style.transform = `translate(${translateX}px, ${translateY}px) scale(${scale})`;
}
// Mouse wheel zoom
modal.addEventListener('wheel', function(e) {
e.preventDefault();
const delta = e.deltaY * -0.001;
scale = Math.min(Math.max(scale + delta, 0.5), 3);
applyTransform();
});
// Touch gestures for mobile
let initialDistance = 0;
modal.addEventListener('touchstart', function(e) {
if (e.touches.length === 2) {
initialDistance = Math.hypot(
e.touches[0].pageX - e.touches[1].pageX,
e.touches[0].pageY - e.touches[1].pageY
);
}
});
modal.addEventListener('touchmove', function(e) {
if (e.touches.length === 2) {
e.preventDefault();
const currentDistance = Math.hypot(
e.touches[0].pageX - e.touches[1].pageX,
e.touches[0].pageY - e.touches[1].pageY
);
const delta = (currentDistance - initialDistance) * 0.01;
scale = Math.min(Math.max(scale + delta, 0.5), 3);
initialDistance = currentDistance;
applyTransform();
}
});
// Add click event to all images
document.querySelectorAll('img:not(#modalImage)').forEach(function(img) {
img.style.cursor = 'pointer';
img.addEventListener('click', function() {
modal.style.display = 'flex';
modalImg.src = this.src;
document.body.style.overflow = 'hidden';
scale = 1;
translateX = 0;
translateY = 0;
applyTransform();
setTimeout(function() {
modal.classList.add('show');
}, 10);
});
});
// Close modal on click
function closeModal() {
modal.classList.remove('show');
setTimeout(function() {
modal.style.display = 'none';
document.body.style.overflow = 'auto';
}, 300);
}
closeBtn.onclick = closeModal;
modal.onclick = function(e) {
if (e.target === modal) closeModal();
};
// Close on escape key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') closeModal();
});
// Image dragging
modalImg.addEventListener('mousedown', function(e) {
isDragging = true;
startX = e.clientX - translateX;
startY = e.clientY - translateY;
modalImg.style.cursor = 'grabbing';
});
document.addEventListener('mousemove', function(e) {
if (isDragging) {
translateX = e.clientX - startX;
translateY = e.clientY - startY;
applyTransform();
}
});
document.addEventListener('mouseup', function() {
isDragging = false;
modalImg.style.cursor = 'grab';
});
});
'''
if soup.body:
soup.body.append(script_tag)
# Add CSS styles to improve design
style_tag = soup.new_tag('style')
style_tag.string = '''
:root {
--primary-gradient: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
--hover-gradient: linear-gradient(135deg, #2980b9 0%, #2471a3 100%);
--bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #e4e9f2 100%);
--card-shadow: 0 8px 20px rgba(0,0,0,0.08);
--transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
body {
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
line-height: 1.7;
padding: 30px;
max-width: 1400px;
margin: 0 auto;
background: var(--bg-gradient);
color: #2c3e50;
min-height: 100vh;
}
.breadcrumb {
display: flex;
flex-wrap: wrap;
gap: 15px;
align-items: center;
padding: 20px;
background: rgba(255, 255, 255, 0.98);
border-radius: 16px;
box-shadow: var(--card-shadow);
margin-bottom: 30px;
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.8);
}
.breadcrumb a {
text-decoration: none;
color: #3498db;
padding: 8px 16px;
border-radius: 8px;
transition: var(--transition);
font-weight: 500;
background: rgba(52, 152, 219, 0.1);
}
.breadcrumb a:hover {
background: var(--primary-gradient);
transform: translateY(-2px);
color: white;
}
.breadcrumb > span:after {
content: '›';
margin-left: 15px;
color: #95a5a6;
font-size: 1.4em;
font-weight: 300;
}
ul {
list-style: none;
padding: 0;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 20px;
margin: 30px 0;
}
li {
background: rgba(255, 255, 255, 0.98);
border-radius: 16px;
overflow: hidden;
transition: var(--transition);
box-shadow: var(--card-shadow);
border: 1px solid rgba(255, 255, 255, 0.8);
}
li:hover {
transform: translateY(-5px);
box-shadow: 0 12px 25px rgba(0,0,0,0.1);
}
li a {
display: block;
padding: 20px;
text-decoration: none;
color: #2c3e50;
font-weight: 500;
transition: var(--transition);
background: rgba(255, 255, 255, 0.98);
}
li a:hover {
background: var(--primary-gradient);
color: white;
}
table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
background: rgba(255, 255, 255, 0.98);
border-radius: 16px;
overflow: hidden;
box-shadow: var(--card-shadow);
margin: 30px 0;
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.8);
}
td {
padding: 20px;
border: 1px solid rgba(236, 240, 241, 0.8);
transition: var(--transition);
}
tr:nth-child(even) {
background: rgba(245, 247, 250, 0.5);
}
tr:hover {
background: var(--bg-gradient);
transform: scale(1.002);
}
img {
border-radius: 16px;
box-shadow: var(--card-shadow);
transition: var(--transition);
max-width: 100%;
height: auto;
display: block;
margin: 10px 0;
}
img:hover {
transform: scale(1.03);
box-shadow: 0 12px 25px rgba(0,0,0,0.15);
}
.open-image-btn {
display: inline-block;
margin: 15px 0;
padding: 12px 24px;
background: var(--primary-gradient);
color: white !important;
border-radius: 12px;
text-decoration: none;
transition: var(--transition);
font-weight: 500;
box-shadow: var(--card-shadow);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.open-image-btn:hover {
background: var(--hover-gradient);
transform: translateY(-3px);
box-shadow: 0 12px 25px rgba(0,0,0,0.15);
}
hr {
border: none;
height: 1px;
background: linear-gradient(to right, transparent, rgba(44, 62, 80, 0.2), transparent);
margin: 30px 0;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.9);
z-index: 1000;
justify-content: center;
align-items: center;
opacity: 0;
transition: opacity 0.3s ease;
}
.modal.show {
opacity: 1;
}
.modal img {
max-width: 90%;
max-height: 90vh;
margin: auto;
display: block;
box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
transform: scale(0.9);
transition: transform 0.3s ease;
cursor: grab;
transform-origin: center center;
}
.modal.show img {
transform: scale(1);
}
.zoom-controls {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 10px;
z-index: 1001;
}
.zoom-btn {
background: rgba(255, 255, 255, 0.2);
border: 1px solid rgba(255, 255, 255, 0.4);
color: white;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: all 0.2s ease;
}
.zoom-btn:hover {
background: rgba(255, 255, 255, 0.3);
}
.close {
position: absolute;
top: 15px;
right: 25px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
cursor: pointer;
z-index: 1001;
transition: color 0.3s ease;
}
.close:hover {
color: #3498db;
}
@media (max-width: 768px) {
body { padding: 15px; }
.breadcrumb {
flex-direction: column;
align-items: flex-start;
padding: 15px;
}
ul {
grid-template-columns: 1fr;
gap: 15px;
}
table { font-size: 14px; }
td { padding: 12px; }
.open-image-btn {
width: 100%;
text-align: center;
}
.modal img {
max-width: 95%;
max-height: 95vh;
}
.close {
top: 10px;
right: 15px;
}
}
'''
# Check if head exists, if not create it
if not soup.head:
head_tag = soup.new_tag('head')
if soup.html:
soup.html.insert(0, head_tag)
else:
html_tag = soup.new_tag('html')
html_tag.append(head_tag)
soup.append(html_tag)
soup.head.append(style_tag)
# Convert navigation links to breadcrumb
nav_links = soup.find_all('a', href=True)
breadcrumb_div = soup.new_tag('div')
breadcrumb_div['class'] = 'breadcrumb'
# Find the main navigation container
nav_container = None
for link in nav_links:
if link.parent.name == 'font' and link.parent.parent.name == 'td':
nav_container = link.parent.parent
break
if nav_container:
nav_links = nav_container.find_all('a', href=True)
current_span = None
for link in nav_links:
# Skip empty links or those without text
if not link.string or not link.string.strip():
continue
# Skip navigation arrows and special characters
if any(char in link.string for char in ['>', '<', '→', '←']):
continue
# Create new span for each link
current_span = soup.new_tag('span')
breadcrumb_div.append(current_span)
# Clone the link to avoid modifying original
new_link = soup.new_tag('a', href=link['href'])
new_link.string = link.string.strip()
current_span.append(new_link)
# Replace old navigation with new breadcrumb if we found valid navigation
if nav_container:
nav_container.replace_with(breadcrumb_div)
# Create a Flask response object with filtered content
response = Response(
soup.encode(),
status=resp.status_code,
content_type='text/html; charset=utf-8'
)
else:
# Create a Flask response object with original content
response = Response(
resp.content,
status=resp.status_code
)
# Copy headers from the target response
for key, value in resp.headers.items():
if key.lower() not in ('transfer-encoding', 'content-encoding', 'content-length'):
response.headers[key] = value
# Copy cookies from target response
for cookie in resp.cookies:
response.set_cookie(
key=cookie.name,
value=cookie.value,
# domain=cookie.domain,
path=cookie.path,
expires=cookie.expires,
secure=cookie.secure,
httponly=cookie.httponly
)
return response
except requests.RequestException as e:
logger.error(f"Error forwarding request: {str(e)}")
return Response(f"Error forwarding request: {str(e)}", status=500)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True) |