1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
makkiz [27]
3 years ago
7

You have been tasked with building a URL file validator for a web crawler. A web crawler is an application that fetches a web pa

ge, extracts the URLs present in that page, and then recursively fetches new pages using the extracted URLs. The end goal of a web crawler is to collect text data, images, or other resources present in order to validate resource URLs or hyperlinks on a page. URL validators can be useful to validate if the extracted URL is a valid resource to fetch. In this scenario, you will build a URL validator that checks for supported protocols and file types.
What you need to do?
1. Writing detailed comments and docstrings
2. Organizing and structuring code for readability
3. URL = :///
Steps for Completion
Task
Create two lists of strings - one list for Protocol called valid_protocols, and one list for storing File extension called valid_ftleinfo . For this take the protocol list should be restricted to http , https and ftp. The file extension list should be hrl. and docx CSV.
Split an input named url, and then use the first element to see whether the protocol of the URL is in valid_protocols. Similarly, check whether the URL contains a valid file_info.
Task
Write the conditions to return a Boolean value of True if the URL is valid, and False if either the Protocol or the File extension is not valid.
main.py х +
1 def validate_url(url):
2 *****Validates the given url passed as string.
3
4 Arguments:
5 url --- String, A valid url should be of form :///
6
7 Protocol = [http, https, ftp]
8 Hostname = string
9 Fileinfo = [.html, .csv, .docx]
10 ***
11 # your code starts here.
12
13
14
15 return # return True if url is valid else False
16
17
18 if
19 name _main__': url input("Enter an Url: ")
20 print(validate_url(url))
21
22
23
24
25
Computers and Technology
1 answer:
mixas84 [53]3 years ago
4 0

Answer:

Python Code:

def validate_url(url):

#Creating the list of valid protocols and file name extensions

valid_protocols = ['http', 'https', 'ftp']

valid_fileinfo = ['.html', '.csv', '.docx']

#splitting the url into two parts

url_split = url.split('://')

isProtocolValid = False

isFileValid = False

#iterating over the valid protocols and file names for validity

for x in valid_protocols:

if x in url_split[0]:

isProtocolValid = True

break

for x in valid_fileinfo:

if x in url_split[1]:

isFileValid = True

break

#Returning the result if the URL has both valid protocol and file extension

return (isProtocolValid and isFileValid)

url = input("Enter an URL: ")

print(validate_url(url))

Explanation:

The image of the output code is attached. Hope it helps.

You might be interested in
If you need to grasp the topic of a document quickly, which strategy can you follow? A. guessing from context B. paraphrasing C.
Lynna [10]

If you need to grasp the topic of a document quickly, you can use previewing. Correct answer: C

With previewing the document you will get an idea of what it is about without actually reading the main body of the document. Previewing includes reading the the title and author details, reading only the parts that ‘jump out’; that is: main headings and sub headings and examining any illustrations, graphs, tables..

8 0
3 years ago
Read 2 more answers
1. What are the two things the base of a number system tells you? After describing these two things, illustrate each with exampl
Alexxx [7]
Using our normal decimal numbering system, the base of a number system, for example 8, tells us two things

1. Each digit is an integer that uses numbers from 0 to 7. There are 8 possible values for a digit
2. We multiply each digit by a power of 8 depending on the position of the digit.

If we use number 112 to (base 8), then; 

<span>(1 x 8 to the power of 2) + (1 x 10 to the power of 1) + (2 x 8 to the power of 0).   </span>


3 0
4 years ago
What are the first two models, e.g. diagrams that affect the entire system, that are built during the CoreProcess to discover an
mrs_skeptik [129]

Answer:

The answer is "Option c and Option d".

Explanation:

A diagram for a case use is a UML dynamic or computational diagram, that is used in the case diagram model. It consists of a set of actions, services, and functions to be carried out by the system. and The class diagram refers to relationships between the UML classes and the source code that dependence, that is two diagrams that affect the system and others are wrong, which can be explained as follows:

  • In option a, It is used for business process, that's is not correct.
  • In option b, It is used for both professionals industry like software and business, that's why it is wrong.
  • In option e, It is used in only high-level language, that's why it is wrong.
  • In option f, It is used to adjust its layout that's why it is wrong.

3 0
4 years ago
The development of computer languages is classified into two categories .<br><br>true or false​
Vikki [24]

Answer:

False

Explanation:

Mark me as a brainliest

6 0
3 years ago
Which part of project management takes deadlines into consideration?
Bess [88]

Answer:

resources because it is the resources that has the second authority over a business

4 0
3 years ago
Read 2 more answers
Other questions:
  • Carl sent an e-mail to more than three thousand employees about a software update. The employees need to prepare for this update
    7·2 answers
  • I need HELP ASAP! 30 POINTS to the RIGHT answer.
    12·2 answers
  • Amazon uses a customer profiling system whenever a customer visits its website. Using this system, Amazon can offer products tai
    8·1 answer
  • Which software fits into the category of a productivity software?
    11·1 answer
  • What are the three primary separation of concerns on the client-side of a dynamic web application? (Check all that apply)
    13·1 answer
  • Dividing a hard drive into multiple sections is known as partitioning
    5·1 answer
  • The basics of color theory assume what central tenets
    14·1 answer
  • The physical layer of the OSI model is not foundational to any of the other layers. True or False
    8·1 answer
  • What is the first step of viewing a web page as described in the video?
    5·1 answer
  • Write a Python program called wdcount.py which uses a dictionary to count the number of occurrences of each word (ignoring case)
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!