How can I change my code to be able to Rank States by population from urllib.request import urlopen as uReq from bs4 import BeautifulSoup as soup URL = 'http://books.toscrape.com/' uClient = uReq(URL) page_html = uClient.read() page_soup = soup(page_html, "html.parser") bookshelf = page_soup.findAll("li", {"class": "col-xs-6 col-sm-4 col-md-3 col-lg-3"}) filename = ("books.csv") f = open(filename, "w") headers = "Book title, Price\n" f.write(headers) for books in bookshelf: bookt = books.h3.a["title"] bookp = books.findAll("p", {"class": "price_color"}) price = bookp[0].text.strip() print("Book Title :" + bookt) print("Book Price :" + price) f.write(bookt + "," + price + "\n") uClient.close() f.close()
How can I change my code to be able to Rank States by population
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
URL = 'http://books.toscrape.com/'
uClient = uReq(URL)
page_html = uClient.read()
page_soup = soup(page_html, "html.parser")
bookshelf = page_soup.findAll("li", {"class": "col-xs-6 col-sm-4 col-md-3 col-lg-3"})
filename = ("books.csv")
f = open(filename, "w")
headers = "Book title, Price\n"
f.write(headers)
for books in bookshelf:
bookt = books.h3.a["title"]
bookp = books.findAll("p", {"class": "price_color"})
price = bookp[0].text.strip()
print("Book Title :" + bookt)
print("Book Price :" + price)
f.write(bookt + "," + price + "\n")
uClient.close()
f.close()
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images