Question

Write a simple python program to crawl 10 pages from the web and store the text...

Write a simple python program to crawl 10 pages from the web and store the text content in the pages into csv file. You code, the 10 html pages, and the csv file which store the content in the pages should be submitted.

Tips: you can write your own program by referencing this tutorial: https://codeburst.io/scraper-b82146396249

Tips2:

(1) If you use python2 on your computer, you can use the following code to get web pages:

import urllib2

page = urllib2.urlopen('https://www.pythonforbeginners.com/')

print page.info()
print page.read()

(2) If you use python3 on your computer, you can use the following code to get web pages:

import urllib.request
page = urllib.request.urlopen('https://www.pythonforbeginners.com/')

print (page.info())
print (page.read())

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here the page https://www.pythonforbeginners.com is scrapped using the module import urllib.request, python 3.6. Inside a for loop, the page is paginated with the pagination value, and scrapped the web page. This content is written to the sites.csv file in /tmp directory.(Please provide your path to the csv file), using csv module.

#CODE STARTS HERE

import csv #Import csv module
import urllib.request #Import csv urllib

def siteCrawler(): #Method starts here
f = csv.writer(open('/tmp/sites.csv', 'w')) #create a file in directory /tmp named sites.csv in write mode[Provide your path of csv file]
for x in range(1, 11): #loops 1 to 10
page=urllib.request.urlopen('https://www.pythonforbeginners.com/?page='+str(x))# Crwal the site with pagination
print(page.read())#print the page content
f.writerow(page.read())#write the page content to the sites.csv file

#CODE ENDS HERE

Add a comment
Know the answer?
Add Answer to:
Write a simple python program to crawl 10 pages from the web and store the text...
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
  • Read a form on a web page Write a CGI program (in C++) that will provide...

    Read a form on a web page Write a CGI program (in C++) that will provide 'added value'. The user is to key in a value (or select a value) in an HTML page and then run the CGI program. The program is to return a page containing useful information that is different from but related to what was keyed in. You may NOT use redirection - i.e. YOU have to provide the content of the page returned. You should...

  • implement a program that reads a word and opens one of the following web pages based...

    implement a program that reads a word and opens one of the following web pages based on the word provided: (name it file 1.html) Word                Site Twitter              twitter web site Facebook         Facebook web site yahoo               yahoo web site If the provided word is not part of the above table, your program will open a page called error.html. The error.html page is a page you will define that will display the message "We cannot process your request". Use...

  • Creating the Home and Template Pages Overview In this assignment, you will start building your Web...

    Creating the Home and Template Pages Overview In this assignment, you will start building your Web site for your fictional organization by creating a homepage using HTML5 and some of the key elements that define a Web page. You are required to use either a simple text editor to write your code, or an enhanced text editor such as Brackets. Note: Microsoft Word is not a good tool for developing code because it is a document processor and not a...

  • Write a PYTHON program that does the following: (instructions in the picture) Please use a 3.5...

    Write a PYTHON program that does the following: (instructions in the picture) Please use a 3.5 version; You can use this website to write the code and then share the link here; because if you write the code and post here, it will have a problem with the indentations https://repl.it/languages/python3

  • python Write a program that calculates the AT and GC content (i.e. the percentage of G...

    python Write a program that calculates the AT and GC content (i.e. the percentage of G and C, and the percentage of A and T) in a given sequence. You can make up your own dummy sequence and store it in text file (use something like Notepad, not word!). Your program should read in the sequence from the file and calculate the GC and AT content. Print out the results to a file called DNA_Statistics.txt, the result should look something...

  • python Create a program to open a text file for reading, find the maximum number in...

    python Create a program to open a text file for reading, find the maximum number in the file, determine if that maximum number is even, and write to an output text file. You should either write Yes if the number is even, otherwise write the maximum number. You should note the following: • Your input file must be named input.txt • The input file has one integer number per line • Your output file must be named output.txt • Your...

  • Design a program using Python and using from flask Import flask that generates a lottery number...

    Design a program using Python and using from flask Import flask that generates a lottery number but in a website.. The program should have an Integer array with 9 elements. Write a loop that steps through the array, randomly generating a number in the range of 0 through 42 for each element. (Use the random function) Then write another loop that displays the contents of the array. Each number should be displayed as a list, the numbers should be generated...

  • Write a Python program to read lines of text from a file. For each word (i.e,...

    Write a Python program to read lines of text from a file. For each word (i.e, a group of characters separated by one or more whitespace characters), keep track of how many times that word appears in the file. In the end, print out the top twenty counts and the corresponding words for each count. Print each value and the corresponding words, in alphabetical order, on one line. Print this in reverse sorted order by word count. You can assume...

  • JAVA Code: Complete the program that reads from a text file and counts the occurrence of...

    JAVA Code: Complete the program that reads from a text file and counts the occurrence of each letter of the English alphabet. The given code already opens a specified text file and reads in the text one line at a time to a temporary String. Your task is to go through that String and count the occurrence of the letters and then print out the final tally of each letter (i.e., how many 'a's?, how many 'b's?, etc.) You can...

  • Hi I'm trying to write a code for a web server in python with flask. This...

    Hi I'm trying to write a code for a web server in python with flask. This is what I have so far from flask import Flask app = Flask(__name__) @app.route('/') #first endpoint i.e. "http://localhost/" def index(): return 'hello' #return data in string if __name__ == '__main__': app.run(debug=True) After running the code, I'm given a address to the web with the text hello. The problem is that this only works with my computer that is running the code. If I try...

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