2

私は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」などの単純な単語で問題なく動作します。次のステップは、Excel 用の pyxll アドインを使用して、同じタスクのために 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

この後、エクセルを起動するとエラーになります。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 は一緒に使用できないようです。助けてください!!!

4

2 に答える 2

0

pywin32をインストールしましたか? Python が Excel などの Windows アプリとやり取りするには、これが必要です。

于 2014-09-09T16:19:30.720 に答える