Question

Write a python program that prompts the user for a web address (full url, html page)...

Write a python program that prompts the user for a web address (full url, html page) and then uses the BeautifulSoup and urllib to read its data.

You can use the any html page you'd like:

The program should output the following:

  1. The page title (hint: read the content from the metatag "title")
  2. The total number of words on the page
  3. The total number of unique words on the page
  4. The total number of each heading used on the page (hint: count the number of "H1"-"H6" header tags used on the page)
  5. The total number of paragraphs on the page (hint: use the <p> tag to count)
  6. The total number of links on the page
  7. After outputting, the program should ask the users if they would like to parse another web address or quit.
  8. Use at least 3 web addresses to check your program. List their urls as comments in the beginning of your program.

Remember:

  • Only use the material covered in this module -- do not use more advanced functions not covered yet in the course
  • Make sure to include comments that explain all your steps (starts with #). Also use a comment to sign your name at the beginning of the program!
  • Work individually and only submit original work
  • Run the program a few times to make sure it executes and meets all the requirements
  • Submit a .py file!

Homework Answers

Answer #1

GIVEN:

write a python program that prompts the user for the web address (full, url, html page ) and then uses the Beautifulsoap and urllib to read its data.

PROGRAM:

from urllib import urlopen

from bs4 import BeautifulSoup // header files

url = input("Enter the url: ")

r = request.get(url)

soup = BeautifulSoup(r.content) // getting input from user

text_p = (' '.join(s.findAll(text = True)) for s in soup.findAll('p'))

c_p = Counter((x.rstrip(punctuation).lower() for y in text_p for x in y.split()))

text_div = (' '.join(s.findAll(text = True)) for s in soup.findAll('div'))

c_div = Counter((x.rstrip(punctuation).lower() for y in text_div for x in y.split()))

total = c_div + c_p

print(total) // total number of words on page

c_H1 = c_H2 = c_H3 = c_H4 = c_H5 = c_H6 = 0

for tag in soup.findAll():

if(tag.name =="H1" or tag.name == "<H1>):

c_H1 = c_H1+1

if(tag.name =="H2" or tag.name == "<H2>):

c_H2 = c_H2+1

if(tag.name =="H3" or tag.name == "<H3>):

c_H3 = c_H3+1

if(tag.name =="H4" or tag.name == "<H4>):

c_H4 = c_H4+1

if(tag.name =="H5" or tag.name == "<H5>):

c_H5 = c_H5+1

if(tag.name =="H6" or tag.name == "<H6>):

c_H6 = c_H6+1 // header tags used on the page

print(c_H1)

print(c_H2)

print(c_H3)

print(c_H4)

print(c_H5)

print(c_H6)

count = 0

for tag in soup.findAll(): // total number of paragraphs on the page

if(tag.name == 'p' or tag.name == '<p>)

count = count+1

print(count)

print(len(soup.find_all('img')))

count = 0

for link in soup.find_all('a', href = True): // total number of links on the page

count = count+1

print(count)

title = soup.find("meta", property="og:title")

print(title)

des = soup.find("meta", property = "og:description")

print(des)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Develop a personal web page for yourself using HTML, CSS, and Javascript Use the following HTML...
Develop a personal web page for yourself using HTML, CSS, and Javascript Use the following HTML tags to design your webpage <h1>...</h1>, <h3>...</h3>,<h6>...</h6>,<p>...</p>,<b>...</b>,<i>...</i>,<a>...</a>,<img>, <table> ... </table>, <div> ... </div>, <form> ... </form>, <input type ="text">, and <input type ="submit"> Use an external css to change the default style of your webpage. You must use at least one element selector, one id selector, and one class selector Using text input and submit button, allow the user to change the background color...
8- Develop a personal web page for yourself using HTML, CSS, and Javascript Use the following...
8- Develop a personal web page for yourself using HTML, CSS, and Javascript Use the following HTML tags to design your webpage <h1>…</h1> , <h3>… </h3> , <h6>… </h6> , <p>…</p> , <b> …</b> , <i>…</ i>, <a…..> </a>, <img…..> , <table>….</table> , <div> …</div>, <form>…</ form>, <input type=“text”>, and <input type=“submit”> Use an external css to change the default style of your webpage. You must use at least one element selector, one id selector, and one class selector Using...
html/php 1. Create an html page (with an html file ending) that contains a form. This...
html/php 1. Create an html page (with an html file ending) that contains a form. This form will accept a number from the user. The form will then send this number to the assignment3.php program by using either GET or POST. 2. The assignment3.php program will read the value in the textbox and place it into the variable "myvalue". The program will then use either a switch statement or IF/THEN/ELSE statement to determine if the value entered is within 10...
In Python write a program that prompts the user for a file name, make sure the...
In Python write a program that prompts the user for a file name, make sure the file exists and if it does reads through the file, count the number of times each word appears and then output the word count in a sorted order from high to low. The program should: Display a message stating its goal Prompt the user to enter a file name Check that the file can be opened and if not ask the user to try...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
Write a python program that will perform text analysis on an input text using all of...
Write a python program that will perform text analysis on an input text using all of the following steps: 1. Take the name of an input file as a command line argument. For example, your program might be called using python3 freq.py example1 to direct you to process a plain text file called example. More information is given on how to do this below. 2. Read the contents of the file into your program and divide the text into a...
You have one Question, Which have four parts, 1st... PHP scriptIn a HTML document, use PHP...
You have one Question, Which have four parts, 1st... PHP scriptIn a HTML document, use PHP to obtain the following :The user will write a sentence as a value of a predefined variable.The output should look like this :The sentence you entered is :This is my sentenceIt is composed of :• 4 different words• 19 characters (including spaces)Note : Your program should make sure the final output is in lower case with the first letter in upper case. 2nd... PHP...
Project File Processing. Write a program that will read in from input file one line at...
Project File Processing. Write a program that will read in from input file one line at a time until end of file and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespaces,...
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter...
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter 10 numbers. 2. save those numbers in a 32-bit integer array. 3. Print the array with the same order it was entered. 3. Calculate the sum of the numbers and display it. 4. Calculate the mean of the array and display it. 5. Rotate the members in the array forward one position for 9 times. so the last rotation will display the array in...
Python programming Write a program that prompts the user to input the three coefficients a, b,...
Python programming Write a program that prompts the user to input the three coefficients a, b, and c of a quadratic equationax2+bx+c= 0.The program should display the solutions of this equation, in the following manner: 1. If the equation has one solution, display ONE SOLUTION:, followed by the solution, displayed with4 digits printed out after the decimal place. 2. If the equation has two real solutions, display TWO REAL SOLUTIONS:, followed by the two solutions, each displayed with4 digits printed...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT