Как собрать воедино простое веб-приложение для колб - PullRequest
0 голосов
/ 29 октября 2019

Я пытаюсь создать небольшое веб-приложение. Простой ценовой скребок. Я пытаюсь собрать его вместе в веб-приложение безуспешно.

Вот мой рабочий фрагмент кода Python, который у меня есть, который возвращает цену конкретного элемента: 918193-012

По сути, идея такова: пользователь вводит код товара, а взамен, на той же странице или другой странице, он получает цену за этот товар. Любые советы приветствуются.

enter image description here

import requests
from bs4 import BeautifulSoup
import subprocess

url = f'https://www.tennis.fr/catalogsearch/result/?q=918193-012'

response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
capturedPrice = soup.findAll('p', class_="special-price")[0].text
capturedPrice = capturedPrice.strip('0')
capturedPrice = capturedPrice.strip()

print(capturedPrice[35:])

Вот мой app.py

from flask import Flask, jsonify, render_template, request
from bs4 import BeautifulSoup
import subprocess

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

if __name__ == '__main__':
    app.run(debug=True)

А вот: index.html

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono&display=swap" > 
<style>
body {
  font-family: 'Roboto Mono', monospace;
}

* {
  box-sizing: border-box;
}

form.example input[type=text] {
  padding: 10px;
  font-size: 17px;
  border: 1px solid grey;
  float: left;
  width: 80%;
  background: #f1f1f1;
}

form.example button {
  float: left;
  width: 20%;
  padding: 10px;
  background: #2196F3;
  color: white;
  font-size: 17px;
  border: 1px solid grey;
  border-left: none;
  cursor: pointer;
}

form.example button:hover {
  background: #0b7dda;
}

form.example::after {
  content: "";
  clear: both;
  display: table;
}
</style>
</head>
<body>
<center>
<h1>Find the best prices</h1>
<p><h4>Stock code to test: 918193-012</h3></p>
<form class="example" action="" style="margin:auto;max-width:500px">
  <input type="text" placeholder="Stock code" name="">
  <button type="submit"><i class="fa fa-search"></i></button>
</form>
</center>
</body>
</html> 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...