Question: Google Colab Use Google Colab and do the following tasks Rename your Notebook tohw10.ipynb Mount Google Drive (!curlipecho.net/plain #ipaddress ! echo '' fromgoogle.colabimportdrive drive.mount( '/content/gdrive'

Google Colab

Use Google Colab and do the following tasks

Rename your Notebook tohw10.ipynb

Mount Google Drive (!curlipecho.net/plain#ipaddress !echo'' fromgoogle.colabimportdrive drive.mount('/content/gdrive')#mountgoogledrive !curlhttps://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh--outputanaconda.sh#downloadanaconda3.8 !bashanaconda.sh-b-p/root/anaconda3-f>/dev/null2>&1#installanaconda3silently ! ~/anaconda3/bin/pythongdrive/MyDrive/tmp/exercise1.py#executesomepythonfile ! cd gdrive/MyDrive/tmp && ~/anaconda3/bin/pythonexercise1.py#analternativewaytoexecutesomepythonfile(changedirectoryfirst,thenuserelativepath) 

Create a folder in Google Drive usingcommand linesin Colab.

oThe path to mounted Google Drive should be/content/gdrive/MyDrive/

oThe folder name isHW10

Download Anaconda 3.8

  • Modify the following code

( import requests

  • from bs4 import BeautifulSoup
  • import csv
  • # initialize http headers
  • headers = {
  • 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36'
  • }
  • # send get request to target url using specified headers
  • response = requests.get('https://phys.org/technology-news/', headers=headers)
  • # get html text from http GET request
  • html = response.text
  • # create BeautifulSoup soup object named soup
  • soup = BeautifulSoup(html, 'html.parser')
  • # find in soup all article tags with specified class attribute
  • articles = soup.find_all('article', {'class': 'sorted-article'})
  • # initialize list to store article data
  • data = []
  • # loop through each article in articles
  • for article in articles:
  • # get title
  • title = article.find('a', {'class':'news-link'}).text
  • # get link to article
  • link = article.find('a', {'class':'news-link'}).get('href')
  • # get sub-category
  • subcat = article.find('div', {'class': 'text-low text-uppercase'}).text.strip()
  • # get relative time
  • reltime = articles[0].find_all('p', {'class': 'text-uppercase text-low'})[0].text.strip()
  • # get comment count
  • comments = articles[0].find_all('p', {'class': 'text-uppercase text-low'})[1].text.strip()
  • # get forward count
  • forwards = articles[0].find_all('p', {'class': 'text-uppercase text-low'})[2].text.strip()
  • # append article info to data list
  • data.append([title, link, subcat, reltime, comments, forwards])
  • # open csv file to write data
  • with open('tech_news.csv', 'w') as file:
  • # create csv writer object
  • writer = csv.writer(file)
  • # write header row
  • writer.writerow(['title', 'url', 'subcategory', 'time', 'comments', 'forwards'])
  • # write the data rows
  • writer.writerows(data) )

code and upload it to the newly created folder inweb browser

oThe output filepath (CSV file) should be customized for Colab in theHW10folder

Execute the modified code with Anaconda 3.8 usingcommand lines

Note: the `command lines` in the requirements refer to the Ubuntu Terminal commands after ! in Notebook

Submission

Submit thehw10.ipynbin `Colab Notebooks` in your Google Drive to Canvas

Submit the link to the newly created folder,HW10. In this folder, it should contain

oThe modified program

oThe CSV file generated by this file

oFor sharing the folder on Google Drive, set `Anyone with the link`

Make sure your URL works in incognito mode

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!