Nov-30-2019, 11:45 AM
Hi guys, this is my first post and my apologies in advance if I missed out something.
I'm learning about Python and doing web scraping with regex then get the results and export it to an Excel file with Pandas. At first, I was using VS Code then switched to Jupyter Lab. There were no code errors, but once I run my .py file I get this strange error that I had never seen before and I can't find it with Google too.
The strange part is on Windows, I'm able to successfully export to Excel although it still throws the same error but on a Mac, it will still be exported but I can't open it and Excel says the file is corrupted.
I'm learning about Python and doing web scraping with regex then get the results and export it to an Excel file with Pandas. At first, I was using VS Code then switched to Jupyter Lab. There were no code errors, but once I run my .py file I get this strange error that I had never seen before and I can't find it with Google too.
The strange part is on Windows, I'm able to successfully export to Excel although it still throws the same error but on a Mac, it will still be exported but I can't open it and Excel says the file is corrupted.

Error:Traceback (most recent call last):
File "ph_gold_scrape.py", line 53, in <module>
gold_price_df.to_excel("gold_price_scrape.xlsx", sheet_name="Sheet1")
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/generic.py", line 2256, in to_excel
engine=engine,
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/io/formats/excel.py", line 742, in write
writer.save()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/io/excel/_openpyxl.py", line 44, in save
return self.book.save(self.path)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/workbook/workbook.py", line 408, in save
save_workbook(self, filename)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/writer/excel.py", line 293, in save_workbook
writer.save()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/writer/excel.py", line 275, in save
self.write_data()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/writer/excel.py", line 75, in write_data
self._write_worksheets()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/writer/excel.py", line 215, in _write_worksheets
self.write_worksheet(ws)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/writer/excel.py", line 200, in write_worksheet
writer.write()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/worksheet/_writer.py", line 354, in write
self.write_top()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/worksheet/_writer.py", line 98, in write_top
self.write_properties()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/worksheet/_writer.py", line 60, in write_properties
self.xf.send(props.to_tree())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/worksheet/_writer.py", line 294, in get_stream
xf.write(el)
File "src/lxml/serializer.pxi", line 1652, in lxml.etree._IncrementalFileWriter.write
TypeError: got invalid input value of type <class 'xml.etree.ElementTree.Element'>, expected string or Element