简体   繁体   English

在 python raise ValueError("Cannot convert {0.r} to Excel".format(value))

[英]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].textsoup.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.

相关问题 raise ValueError(&quot;无法将 {0!r} 转换为 Excel&quot;.format(value)) - raise ValueError("Cannot convert {0!r} to Excel".format(value)) ValueError:无法转换为 Excel - Python 中的刮板 - ValueError: Cannot convert to Excel - Scrapper in Python 值错误:无法将 [] 转换为 Excel - ValueError: Cannot convert [] to Excel ValueError:无法将0转换为Excel - ValueError: Cannot convert 0 to Excel 如何解决“ ValueError:无法转换为Excel”? (使用Python和openpyxl) - How to solve “ValueError: Cannot convert to Excel”? (Using Python & openpyxl) 使用 raise ValueError python 允许两种日期时间格式 - Allow two datetime format using raise ValueError python ValueError:无法将* .csv内容*转换为excel - ValueError: Cannot convert *.csv stuff* to excel 如何为超过python中特定值的数字引发Valueerror? - How to raise a Valueerror for a number that exceed a specific value in python? Python初学者:提高ValueError(&#39;必须具有相等的len键和值&#39;) - Python beginner : raise ValueError('Must have equal len keys and value ') Python多处理池&#39;raise ValueError(“池未运行”)ValueError:池未运行&#39;函数与返回值 - Python multiprocessing Pool 'raise ValueError("Pool not running") ValueError: Pool not running' function with return value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM