Question

In: Computer Science

UNSURE HOW TO PARSE: I am trying to parse a website with a CSV : import...

UNSURE HOW TO PARSE: I am trying to parse a website with a CSV :

import csv
import requests as r
from bs4 import BeautifulSoup


urltoget = 'a.ttu.edu/2019c/isqs6339/http://drd.bhw1/index.php'
filepath = 'C:\\Users\\Zuliat\\Desktop\\test123.csv'


res = r.get(urltoget)
res.content

if res.status_code == 200:
print (' request is good')
else:
print (' bad request, retrieved code' + str(res.status_code))
  
print (res.content)

soup = BeautifulSoup(res.content,'lxml')
print(soup.title)

They are responding with a message Line 1

Solutions

Expert Solution

You should use a HTML parser when parsing a HTML page.. I am not able to open the page link which you have given.. However, I have written a sample for some of my student earlier, i hope it helps you..

import requests
from bs4 import BeautifulSoup

# Get the HTML contents of URL using requests module
page = requests.get('https://www.tdcj.texas.gov/death_row/dr_executions_by_year.html')

# Create a BS4 Object using the html content
# mention parser as HTML parser.
soup = BeautifulSoup(page.text, 'html.parser')

# Now Soup object has a select method, in which you can mention
# the CSS selector, with which it selects the list of elements
# like, Below i am finding elements with class "overflow", then 
# inside that, i am finding all the table rows
rows = soup.select('.overflow table tr')[1:-1]

# We are trying to find the number of executions on each year from
# the webpage, So we create a dictionary, where we will store the 
# number of executions on each year

executions = {}

for link in rows:
        # on each table rows, th element contains the year
        # while second last td element contains the number of executions
        x = link.find('th')
        y = link.findAll('td')[-2]
        executions[int(x.text)] = int(y.text)

for y in sorted(executions):
        print(y, ':', executions[y])
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

I am trying to create a classified balance sheet and I am unsure what is involved...
I am trying to create a classified balance sheet and I am unsure what is involved when reporting the current assets, liabilities and owners equity?
Python I am creating a class in python. Here is my code below: import csv import...
Python I am creating a class in python. Here is my code below: import csv import json population = list() with open('PopChange.csv', 'r') as p: reader = csv.reader(p) next(reader) for line in reader: population.append(obj.POP(line)) population.append(obj.POP(line)) class POP: """ Extract the data """ def __init__(self, line): self.data = line # get elements self.id = self.data[0].strip() self.geography = self.data[1].strip() self.targetGeoId = self.data[2].strip() self.targetGeoId2 = self.data[3].strip() self.popApr1 = self.data[4].strip() self.popJul1 = self.data[5].strip() self.changePop = self.data[6].strip() The problem is, I get an error saying:  ...
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
I am trying to create a program that reads from a csv file and finds the...
I am trying to create a program that reads from a csv file and finds the sum of total volume in liters of liquor sold from the csv file by county and print that list out by county in descending order. Currently my program runs and gives me the right answers but it is not in descending order. I tried this:     for county, volume in sorted(sums_by_volume.items(), key=lambda x: x[1], reverse=True):         index +=1         print("{}. {} {:.2f}".format(county, sums_by_volume[county]))      When I run...
***** PLEASE solve using MATHCAD, I am unsure on how to solve properly with this application....
***** PLEASE solve using MATHCAD, I am unsure on how to solve properly with this application. Thank you so much! Problem 7: Design a Silicon diode that has a breakdown voltage =20V and has a junction capacitance of 1 pF at no biasing.
I am buying a firm with an expected perpetual cash flow of $630 but am unsure...
I am buying a firm with an expected perpetual cash flow of $630 but am unsure of its risk. If I think the beta of the firm is zero, when the beta is really 1, how much more will I offer for the firm than it is truly worth? Assume the risk-free rate is 6% and the expected rate of return on the market is 18%. (Input the amount as a positive value.) Present value difference            $ ____
I am trying to implement a search function for a binary search tree. I am trying...
I am trying to implement a search function for a binary search tree. I am trying to get the output to print each element preceding the the target of the search. For example, in the code when I search for 19, the output should be "5-8-9-18-20-19" Please only modify the search function and also please walk me through what I did wrong. I am trying to figure this out. Here is my code: #include<iostream> using namespace std; class node {...
I am unsure as to why I cannot solve my Computer Science question I was just...
I am unsure as to why I cannot solve my Computer Science question I was just wondering if someone could show me exactly what they would do the code is in C++: write a program that display the following manual for user to chose among calculations Please select one of the following: addition subtraction multiplication division exit The program will then read in the user entry. when the user chose "1", it will ask the user "Please enter two numbers...
Assignment: Complete the entries. I am unsure on how to do these. 12/31/2018-On December 15, Anniston...
Assignment: Complete the entries. I am unsure on how to do these. 12/31/2018-On December 15, Anniston contracted to perform services for a client and recorded the amount received as Unearned Revenue (amount $1,560). As of December 31, Anniston has earned 60% of this Unearned Revenue. 12/31/2018-Anniston prepaid two months of rent on December 1 ($1,450). This was debited to Prepaid Rent and is included in the Trial Balance. 12/31/2018 A physical count of supplies revealed an ending balance of $500....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT