저는 Python을 처음 사용합니다. 나는 인터넷에서 한 단어의 의미를 얻으려고 노력하고있다. 독립형 파이썬 코드는 잘 작동합니다.pyxll을 사용하여 python을 excel로 통합 ... lxml 모듈에 문제가 발생했습니다.
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을 사용하여 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은 함께 사용하지 않는 것 같다. 도와주세요!!!
예제 코드에서 들여 쓰기를 수정하십시오. –