I'm trying to fetch and export the data in the front page of https://icostats.com/ to a .csv file. This is my code so far:
import csv
from selenium import webdriver
def get_elements_by_xpath(driver, xpath):
return [entry.text for entry in driver.find_elements_by_xpath(xpath)]
url = ("https://icostats.com")
driver = webdriver.Firefox(executable_path=r'C:\Users\alph1\Scrapers\geckodriver.exe')
driver.get(url)
search_entries = [
("NAME", "//div[@class='tdName-0-73']"),
("DATE", "//div[@class='tdDate-0-74']"),
("CUR PRICE", "//div[@class='tdPrice-0-72'][1]"),
("ICO PRICE", "//div[@class='tdPrice-0-72'][0]"),
("24H ROI", "//div[@class='tdPrimary-0-75']")]
with open('textfile.csv', 'wb') as f_output:
csv_output = csv.writer(f_output)
# Write header
csv_output.writerow([name for name, xpath in search_entries])
entries = []
for name, xpath in search_entries:
entries.append(get_elements_by_xpath(driver, xpath))
csv_output.writerows(zip(*entries))
get_elements_by_xpath()
And here is the exception I'm getting.
File "C:/Users/alph1/PycharmProjects/PyQtPS/ICO2CSV.py", line 28, in csv_output.writerow([name for name, xpath in search_entries]) TypeError: a bytes-like object is required, not 'str'
I have a feeling I shouldn't be calling the method like this in the end, but don't know how else I'd do it.