Question

**Python script** to input from user an URL, fetch the page contents using requests, and save...

**Python script** to input from user an URL, fetch the page contents using requests, and save the respective page contents to an appropriately named text file.
Wrap this request code in its own function: eg create a function getPageRequests(url).
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import requests

def getPageRequests(url):

data = requests.get(url)

outfile=open("output.txt","w")

outfile.write(data.text)

print("Data written into output.txt")

outfile.close()

url = input("Enter URL: ")

getPageRequests(url)

----------------------------------------------------------------------------------------------------------------------------------------------------------
SEE OUTPUT/ IMAGE FOR INDENTATION




Thanks, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
**Python script** to input from user an URL, fetch the page contents using requests, and save...
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
  • Write a PHP script that obtains a URL and its description from user and stores the...

    Write a PHP script that obtains a URL and its description from user and stores the information into a database using MySQL. Create and run a SQL script with database named URL and a table named Urltable. The first field of the table should contain an actual URL, and the second, which is named Description, should contain a description of the URL. Use www.deitel.com as the first URL, and input Cool site! as its description. The second URL should be...

  • PYTHON 3.6.1 write a script named copyfile.py. this script should prompt the user for the names...

    PYTHON 3.6.1 write a script named copyfile.py. this script should prompt the user for the names of two text files. the contents of the first file should be input and written to the second file.

  • For Python | Instructions Write a script named difpy. This script should prompt the user for...

    For Python | Instructions Write a script named difpy. This script should prompt the user for the names of two text files and compare the contents of the two files to see if they are the same. 1. If they are the script should simply output "Yes". 2. If they are not the script should output "No", followed by the first lines of each file that differ from each other The input loop should read and compare lines from each...

  • create a python program that requests input from the user for a starting and ending value....

    create a python program that requests input from the user for a starting and ending value. then your program should return all prime numbers between those two values. you will be using input, conditional and control flow statements

  • Create a python script to manage a user list that can be modified and saved to...

    Create a python script to manage a user list that can be modified and saved to a text file. Input text file consisting of pairs of usernames and passwords, separated by a colon (:) without any spaces User choice: (‘n’-new user account, ‘e’-edit existing user account, ‘d’- delete existing user account, ‘l’- list user accounts, ‘q’-quit) List of user accounts, error messages when appropriate Output text file consisting of pairs of username and passwords, separated by a colon (:) without...

  • In Python, make changes in the client code, so that the client allows the user to...

    In Python, make changes in the client code, so that the client allows the user to continue to send multiple requests until the user types in “Quit”. This means that the client process should not exit after the user sends one request and receives one response. Instead, the client process should be able to receive subsequent inputs from the user. You need to have a loop in the client code, so that it can accept the user request until the...

  • Write a python program that prompts the user for the names of two text files and...

    Write a python program that prompts the user for the names of two text files and compare the contents of the two files to see if they are the same. If they are, the scripts should simply output “Yes”. If they are not, the program should output “No”, followed by the first lines of each file that differ from each other. The input loop should read and compare lines from each file. The loop should break as soon as a...

  • Using C# Create a “Main” method that will take user input one line at a time...

    Using C# Create a “Main” method that will take user input one line at a time until they enter the phrase “done”. Store each line entered into an ArrayList, so that one element of the ArrayList is one line of user input. You do NOT need to write your own ArrayList class, please use the standard library implementation of an ArrayList. After the user finishes typing in input, ask the user for a location and file name. Save the contents...

  • Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to...

    Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to symbolically compute the derivative of ln(x) on the interval from -5 to 5, containing 100 data points. Your script file should output a plot of the derivative of ln(x) (taken from your function) vs x. Use a line with circular markers for the plot and include a grid and appropriate labels. The user-defined function should 1. Receive a single x value as input. 2....

  • 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):...

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