[英]In python raise ValueError("Cannot convert {0!r} to Excel".format(value))
In python, I developed parsing program.在python,我开发了解析程序。 My program recived data in website.我的程序在网站上接收到数据。 I want to send Execl cell.我想发送 Execl 单元格。 but I received error message.但我收到错误信息。 I want to solve myself, but I can't I spent 7days this problem.我想解决自己,但我不能 我花了 7 天这个问题。
# -*- coding:utf-8 -*-
from __future__ import unicode_literals
from urllib.request import Request, urlopen
from openpyxl import load_workbook
from bs4 import BeautifulSoup
import pyautogui
pyautogui.FAILSAFE = False
#엑셀 로그인
load_owner_order_wb = load_workbook("order.xlsx", data_only=True)
load_owner_order_ws = load_owner_order_wb['Sheet1']
owner_source = load_owner_source_ws['A1'].value
# html = urlopen(owner_source).read()
html = urlopen('https://ownerclan.com/V2/product/view.php?selfcode=W13B289').read()
soup = BeautifulSoup(html, "html.parser")
i=1
while len(load_owner_order_ws['A']) >= i:
i = i + 1
load_owner_order_ws['A%d'%i] = soup.title.string
load_owner_order_ws['B%d'%i] = soup.find('span', class_='point_color_b2').string
print(soup.select('#productPrice'))
load_owner_order_ws['C%d'%i] = soup.select('#productPrice')
load_owner_order_wb.save("order.xlsx")
Traceback (most recent call last):
File "D:/python/smart_store/owner_clan.py", line 111, in <module>
load_owner_order_ws['C%d'%i] = soup.select('#productPrice')
File "D:\python\smart_store\venv\lib\site-packages\openpyxl\worksheet\worksheet.py", line 313, in __setitem__
self[key].value = value
File "D:\python\smart_store\venv\lib\site-packages\openpyxl\cell\cell.py", line 216, in value
self._bind_value(value)
File "D:\python\smart_store\venv\lib\site-packages\openpyxl\cell\cell.py", line 199, in _bind_value
raise ValueError("Cannot convert {0!r} to Excel".format(value))
ValueError: Cannot convert [<span id="productPrice">8,100</span>] to Excel
I have more experience with OpenPyXl than Beautiful Soup but the error seems to be telling you that soup.select('#productPrice')
is returning [<span id="productPrice">8,100</span>]
or basically a list of HTML elements (that happens to only have one value).与 Beautiful Soup 相比,我对 OpenPyXl 的经验更多,但错误似乎是在告诉您soup.select('#productPrice')
正在返回[<span id="productPrice">8,100</span>]
或基本上是 HTML 的列表元素(碰巧只有一个值)。 If you want the innerHTML value of #productPrice
then try soup.select('#productPrice')[0].text
or soup.find('#productPrice').text
.如果您想要#productPrice
的 innerHTML 值,请尝试soup.select('#productPrice')[0].text
或soup.find('#productPrice').text
。
I may be wrong about the .text
part.我可能对.text
部分有误。 Please refer to Beautiful Soup documentation to figure out how to extract the info you want from HTML!请参考Beautiful Soup 文档来弄清楚如何从 HTML 中提取你想要的信息!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.