python - 使用pyxll将python集成到excel中...... lxml模块有问题

标签 python xml excel lxml pyxll

我是 python 新手。我正在尝试从互联网上获取单词的含义。独立的 python 代码工作得很好。

    from lxml import html
    import requests
    url = "http://dictionnaire.reverso.net/francais-definition/"
    word = raw_input("please enter the word you want to translate ")
    url = url + word
    page = requests.get(url)
    tree= html.fromstring(page.text)
    translation = tree.xpath('//*[@id="ID0EYB"]/text()')
    print translation

请注意,我使用的 xpath 仅用于测试目的。与“manger”、“gonfler”等简单的词配合使用时效果很好。
我正在尝试的下一步是使用 pyxll addin for excel 在 excel 中为同一任务创建一个函数。
   from pyxll import xl_func
   from lxml import html
   import requests
   @xl_func("string x: string")
   def traduction(x):
           url = "http://dictionnaire.reverso.net/francais-definition/"
           url = url + x
           page = requests.get(url)
           tree= html.fromstring(page.text)
           translation = tree.xpath('//*[@id="ID0EYB"]/text()')
           return translation

在此之后,当我启动 excel 时,出现错误。在pyxll的日志文件中,错误描述如下:
  2014-09-09 17:02:41,845 - ERROR : Error importing 'worksheetfuncs': DLL load failed: Le module spécifié est introuvable.
  2014-09-09 17:02:41,845 - ERROR : Traceback (most recent call last):
  2014-09-09 17:02:41,845 - ERROR :   File "pyxll", line 791, in _open
  2014-09-09 17:02:41,845 - ERROR :   File "\pyxll\examples\worksheetfuncs.py", line 317, in <module>
  2014-09-09 17:02:41,845 - ERROR :     from lxml import html
  2014-09-09 17:02:41,846 - ERROR :   File "C:\Python27\lib\site-packages\lxml\html\__init__.py", line 42, in <module>
  2014-09-09 17:02:41,846 - ERROR :     from lxml import etree
  2014-09-09 17:02:41,846 - ERROR : ImportError: DLL load failed: Le module spécifié est introuvable.
  2014-09-09 17:02:41,888 - WARNING : pydevd failed to import - eclipse debugging won't work
  2014-09-09 17:02:41,888 - WARNING : Check the eclipse path in \pyxll\examples\tools\eclipse_debug.pyc
  2014-09-09 17:02:41,890 - INFO : callbacks.license_notifier: This copy of PyXLL is for evaluation or non-commercial use only

我已经使用带有 API 的翻译网站来做类似的事情,而且效果很好。对我来说真正的问题是我使用 lxml 的解析,似乎 lxml 和 pyxll 不能一起使用。请帮忙!!!

最佳答案

你安装了吗pywin32 ? Python 需要与 Excel 等 Windows 应用程序交互。

关于python - 使用pyxll将python集成到excel中...... lxml模块有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25748877/

相关文章:

python - 如何使用 Flask SQLAlchemy 从 mysql 获取有限数量的行?

java - 快速替换 XML 节点值

Java:解析 RSS 提要时出错

c# - 导出DataGridView数据到excel

python - Pandas - 仅删除等于零的连续行

python - flask 在 cookie 中保存民意调查

Python 元素树 : find element by its child's text using XPath

python - 您可以在不同的函数中使用 xlwt 工作簿的同一实例吗?

c# - 是否可以在 C# 中编写将在 Excel 中运行的 ActiveX 控件?

python - selenium.common.exceptions.WebDriverException : Message: unknown error: unable to discover open pages while test execution through InstaPy and selenium