Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementation of user friendly error message #121

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

@app.route("/")
def index():
return redirect(url_for("input"))
return redirect(url_for("index.html"))

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

#setting up backend to receive urls
@app.route('/save_url', methods=['POST'])
Expand Down
2 changes: 1 addition & 1 deletion error_handling.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import csv
import csv
import requests
from requests.exceptions import RequestException
import os
Expand Down
31 changes: 29 additions & 2 deletions templates/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,41 @@
{% block content %}
<div class="form-container">
<h2>Input Webpage URLs</h2>
<form action="" method="POST" class="input-form">
<form action="" method="POST" class="input-form" onsubmit="validateUrl(); return false;">
<textarea rows="5" cols="60" name="url" placeholder="https://example.com/python-page"></textarea>
<label for="depth">Depth of Scraping:</label>
<input type="number" name="depth" value="1" min="1">
</select>
<button class="btn" type="submit">Scrape Data</button>
</form>
</div>
<script>
// Function to check if a URL is valid
function isValidUrl(url) {
// Regular expression for a more permissive URL validation
const urlRegex = /^(ftp|http|https):\/\/[^ "]+$/;

// Allow URLs without specifying the protocol
const urlWithoutProtocolRegex = /^[^ "]+\.[a-zA-Z]{2,}$/;

// Check if the URL matches either of the regular expressions
return urlRegex.test(url) || urlWithoutProtocolRegex.test(url);
}

// Function to validate the entered URL
function validateUrl() {
// Get the URL value from the input field
const userUrl = document.getElementsByName("url")[0].value;

// Check if the URL is valid
if (isValidUrl(userUrl)) {
// Display success message if the URL is valid
console.log("URL is valid. Proceed with the entered URL: " + userUrl);
} else {
// Display error message if the URL is not valid
alert("Hello dear user, the URL you just passed in isn't valid. Example of an appropriate URL is adorsys.com");
}
}
</script>
{% endblock %}
{% block title %}
Input webpages URLs
Expand Down