Added a new location to display url results

This commit is contained in:
alexwholland
2023-01-07 16:25:18 -08:00
parent c9adc314d3
commit a179b64c7d
3 changed files with 34 additions and 2 deletions

View File

@@ -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>

View 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 %}

View File

@@ -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)