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?
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...
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 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 {...
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....
Hi I am having the following problem. At the moment I am trying to create a...
Hi I am having the following problem. At the moment I am trying to create a bode plot for the following function. G(s)=(Ks+3)/((s+2)(s+3)) Note: Not K(s+2)! I then want to plot multiple bode plots for various values of K. Eg. 1,2,3, etc. I am having two separate issues. 1. How do I define the TF with a constant K in the location required (a multiple of s in the numerator) 2. How do I create multiple bode plots for values...
When using the import wizard in MATLAB to import data fro, a .csv file the data...
When using the import wizard in MATLAB to import data fro, a .csv file the data appears in MATLAB in the following format "35:53.2" how do I convert this into more usable matlab values? I think that the duration function was used to generate the time format. The code will need to be written in MATLAB software I will leave feedback if you are able to provide a correct response. Thank you
4. I have reviewed the midterm grades, and I am trying to predict how well the...
4. I have reviewed the midterm grades, and I am trying to predict how well the class will do on the final exam. The frequency values are actual grades for the Summer II midterm: Grade Expected Frequency (Observed) Greater than A 5 7 A 6 9 B 8 4 C 3 4 D 1 0 F 2 1 a. What will be my degrees of freedom? b. What is O-E (difference) for grades of B? c. What is O-E^2 for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT