Aug-29-2017, 09:31 AM
Like this:
from bs4 import BeautifulSoup from urllib.request import urlopen page_url = "http://econpy.pythonanywhere.com/ex/001.html" new_file = "Mynew.csv" f = open(new_file, "w") Headers = "Header1,Header2\n" f.write(Headers) html = urlopen(page_url) soup = BeautifulSoup(html, "html.parser") buyer_info = soup.find_all("div", {"title":"buyer-info"}) for i in buyer_info: Header1 = i.find("div", {"title":"buyer-name"}) Header2 = i.find("span", {"class":"item-price"}) f.write('{},{}\n'.format(Header1.text, Header2.text)) f.close()
Output:Header1,Header2
Carson Busses,$29.95
Earl E. Byrd,$8.37
Patty Cakes,$15.26
Derri Anne Connecticut,$19.25
Moe Dess,$19.25
.......