python - 我需要使用 selenium-chromedriver 在电报机器人中发送复制的文本
问题描述
element = browser.find_element_by_xpath("//div[@class='span12']")
# send the copied text back
context.bot.send_message(chat_id=update.message.chat_id, text=element)
#来个错误
element = browser.find_element_by_xpath("//div[@class='span12']")
2021-10-15 05:34:51,229 - telegram.ext.dispatcher - ERROR - No error handlers are registered, logging exception
........................
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type WebElement is not JSON serializable
解决方案
JSON
只能发送原始类型的数据,但你有 object WebElement
。
您应该手动将其转换为字符串
send_message(..., text=str(element) )
但可能您只是忘记.text
从该对象获取文本。
send_message(..., text=element.text )
推荐阅读
- flutter - 带有颤振桌面应用程序的 ESC/POS 打印机?
- php - 未定义的属性:App\Models\Product::$category Laravel 8
- c# - 如何使我的代码更可重用于登录我的控制器
- vba - 通过 CATIA VBA 宏导入 .obj 文件
- python - 如何使用 re.search 搜索作为转义序列的字符串
- visual-studio-code - 我可以将 VScode 设置为仅在工作区中自动保存文件吗?
- node.js - 如何使用猫鼬合并更新文档?
- javascript - 不满足条件/回调时防止 ararray.map 返回 undefined
- javascript - 如何使用 Javascript 将 csv 和 xlsx 文件读取为 Html 表格形式
- basic-authentication - Yaws 基本身份验证 letencrypt