Question

Write a function to dump the html content, and save it in the same directory of...

Write a function to dump the html content, and save it in the same directory of your python script. The name of the saved html file should include the current time stamp.

I currently have been trying this code. But Repl.it says "ModuleNotFoundError: No module named 'urllib2'". Could someone point out what i am doing wrong and help me include the current time stamp using 'datetime'. The format for the date and time should be YYYY_MM_DD_HH_MM_SS.

import urllib2

def webpagedumb(url):

req = urllib2.Request('https://en.wikipedia.org/wiki/Web_page')

response = urllib2.urlopen(req)

the_page = response.read()

return

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import urllib.request
from datetime import datetime

url = 'https://en.wikipedia.org/wiki/Web_page'
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)

fName = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
f = open(fName + '.html', 'w')
f.write(response.read().decode('utf-8'))
f.close()

print('Completed!')

============

urllib2 is not present in python 3.

Add a comment
Know the answer?
Add Answer to:
Write a function to dump the html content, and save it in the same directory of...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The URL is part of the assignment, it is a web scraper in Wiki. A' Read...

    The URL is part of the assignment, it is a web scraper in Wiki. A' Read aloud A Big-Data Processing Task: We need to find out 15 most frequently used words on a set of Wikipedia pages. Specifically, we need to find out a list of these words and the number of occurrences of each word on the pages. The list should be sorted in descending order based on the number of occurrences. The following is a sample of output...

  • Write a batch script, which combines a few tools in Linux to finish a big-data processing...

    Write a batch script, which combines a few tools in Linux to finish a big-data processing task --- finding out most frequently used words on Wikipedia pages. The execution of the script generates a list of distinct words used in the wikipedia pages and the number of occurrences of each word on these web pages. The words are sorted by the number of occurrences in ascending order. The following is a sample of output generated for 4 Wikipedia pages. 126...

  • 1. Write a function that takes as input a directory. The function will search through that...

    1. Write a function that takes as input a directory. The function will search through that directory and its full subdirectory tree, building a count of the files by their extensions. As in the lecture, use a dictionary to keep track of the counts. The return-value of this function will be a dictionary of (key,value) pairs where the key will be the file extension and the value will be the number of files with that extension. For example, for the...

  • Python 3.6 Question 12 (2θ points) write a function named uniqueWords that counts how many different...

    Python 3.6 Question 12 (2θ points) write a function named uniqueWords that counts how many different words there are in each line of an input file and writes that count to a corresponding line of an output file. The input file already exists when uniqueWords is called. uniquewords creates the output file. Input. The function uniquewords takes two parameters: ◆ inFile, a string that is the name of text file that is to be read. The file that inFile refers...

  • I will like to compare automobile producers. This assignment suppose to read data like div tags...

    I will like to compare automobile producers. This assignment suppose to read data like div tags a etc. And count occurrence of them. Reading from a URL while working with an API (using Mediawiki API as an example) Input: Will be obtained from a URL using Mediawiki API -- starter code below Output: Up to you... sort of. What to submit: Upload a report (.pdf preferred) containing screenshots of code, output, and discussion/conclusions to d2l dropbox. Please also submit your...

  • I need help with turtle graphics assignment in python 3, please! Write a program named Lastname_firstname_clock.py to display a clock face with hands showing the current time. The radius of the clock...

    I need help with turtle graphics assignment in python 3, please! Write a program named Lastname_firstname_clock.py to display a clock face with hands showing the current time. The radius of the clock face (the distance from the center to the hour markers) is 150. The hour hand has length 100, and the minute hand has a length of 120 You may design the clock in one of three ways: using the square cursor shape (hint: stamp)) for the hour markers...

  • Please write this in Java, please write comments as you create it, and please follow the...

    Please write this in Java, please write comments as you create it, and please follow the coding instructions. As you are working on this project, add print statements or use the debugger to help you verify what is happening. Write and test the project one line at a time. Before you try to obtain currency exchange rates, obtain your free 32 character access code from this website: https://fixer.io/ Here's the code: 46f27e9668fcdde486f016eee24c554c Choose five international source currencies to monitor. Each...

  • CIS 221 Loan Calculator Enhancement Introduction You are a systems analyst working for a company that...

    CIS 221 Loan Calculator Enhancement Introduction You are a systems analyst working for a company that provides loans to customers. Your manager has asked you to enhance and correct their existing Loan Calculator program, which is designed to calculate monthly and total payments given the loan amount, the annual interest rate, and the duration of the loan. Although the current version of the program (hereby termed the “As Is” version) has some functionality, there are several missing pieces, and the...

  • Python Coding The script, `eparser.py`, should: 1. Open the file specified as the first argument to...

    Python Coding The script, `eparser.py`, should: 1. Open the file specified as the first argument to the script (see below) 2. Read the file one line at a time (i.e., for line in file--each line will be a separate email address) 3. Print (to the screen) a line that "interprets" the email address as described below 4. When finished, display the total number of email addresses and a count unique domain names Each email address will either be in the...

  • I need HELP to get the code to do these function: If I keep clicking "Generate"...

    I need HELP to get the code to do these function: If I keep clicking "Generate" multiple times, the list keeps on getting bigger. The number of rows should always be equal to the number of columns. Also make the code to show both table at the same time? Here is the code I got some far : Code: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>Testing</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous"> </head> <style> td...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT