I am scraping a price from a website using lxml and I'd like to insert that price into an existing Excel file using openpyxl. When I run the code, I get the error:
ValueError: Cannot convert ['$364'] to Excel
('$364' is the scraped price). How do I fix this? It appears that line 11 of code: sheet['A1'] = price is the problem. My entire code is below:
from lxml import html
import requests
page = requests.get('http://www.randomlengths.com/Woodwire/RL-Lbr-Pnl/')
tree = html.fromstring(page.content)
price = tree.xpath('//*[@id="main-frame"]/div/div[1]/table/tbody/tr[2]/td[2]/strong/text()')
print(price)
import openpyxl
xfile = openpyxl.load_workbook('C:/Users/noah.merkousko/randomlengthslumber.xlsx')
sheet = xfile.get_sheet_by_name('Framing Lumber')
sheet['A1'] = price
xfile.save('random lengths lumber test.xls')