mirror of
https://github.com/Marketscrape/marketscrape-web.git
synced 2026-05-24 13:44:29 -04:00
✨ Added a new location to display url results
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<button class="btn btn-primary" type="submit">Calculate</button>
|
||||
<input type="button" value="Reset" id="resetBtn" onClick="this.form.reset()" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
12
marketscrape/scraper/templates/scraper/result.html
Normal file
12
marketscrape/scraper/templates/scraper/result.html
Normal file
@@ -0,0 +1,12 @@
|
||||
{% extends 'scraper/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<div>
|
||||
<div>
|
||||
<h1>Marketscrape</h1>
|
||||
<h3>The shortened_url is: {{ shortened_url }}</h3>
|
||||
<h3>The mobile_url is: {{ mobile_url }}</h3>
|
||||
<h3>The market_id is: {{ market_id }}</h3>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
@@ -1,11 +1,30 @@
|
||||
from django.shortcuts import render
|
||||
from django.views import View
|
||||
from .forms import MarketForm
|
||||
import re
|
||||
|
||||
class Index(View):
|
||||
def get(self, request):
|
||||
form = MarketForm()
|
||||
return render(request, 'scraper/index.html', {'form': form})
|
||||
|
||||
def post(self, requeset):
|
||||
pass
|
||||
def post(self, request):
|
||||
form = MarketForm(request.POST)
|
||||
|
||||
if form.is_valid():
|
||||
input_url = form.cleaned_data['input_url']
|
||||
|
||||
# Shorten the URL listing to the title of the listing
|
||||
shortened_url = re.search(r".*[0-9]", input_url).group(0)
|
||||
# Use the shortened URL and convert it to mobile, to get the price of the listing
|
||||
mobile_url = shortened_url.replace("www", "m")
|
||||
# Find the ID of the product
|
||||
market_id = (re.search(r"\/item\/([0-9]*)", input_url)).group(1)
|
||||
|
||||
context = {
|
||||
'shortened_url': shortened_url,
|
||||
'mobile_url': mobile_url,
|
||||
'market_id': market_id,
|
||||
}
|
||||
|
||||
return render(request, 'scraper/result.html', context)
|
||||
|
||||
Reference in New Issue
Block a user