1

Before I put my question, I want to say that I have already searched on stackoverflow and several other websites about the problem, but the answers I found were not very satisfying in detail.

My problem is, I need to get a JSON data from an attribute in a HTML tag. I thought that it would be easier to achieve this using Python, and it was quite easy in fact. The code works like a charm. The problem is, I need to use this function in a C# class, so I need to use IronPython. When I import to code to my C# project and use IronPython to run call it, I get an error telling me 'No module named lxml'. According to other questions and posts on the internet on this topic, it is because lxml is not compatible with IronPython.

So I was wondering if it is possible to somehow make it compatible using some other libraries, or by using a replacement for IronPython. I would also very appreciate if you could direct me to any information about libraries I can use instead of lxml.

Here is the piece of code I use the lxml library:

tree = html.fromstring(page.content)

# Get the data-items value from the html
dt = tree.xpath('//*[@id="list-container"]/div[3]/div//table/@data-items')

Also I wonder if xml.etree.ElementTree is compatible with IronPython, and if it is, is there any way I can use both the xpath method and ElementTree instead of lxml and its functions

LoLeRji
  • 51
  • 7
  • try pythonnet for lxml – denfromufa Mar 24 '16 at 19:54
  • tried using pythonnet but it returned me an error, saying 'Unable to load DLL, 'pyhton27: The specified module not found''. It probably is the exact same error the IronPython returned, which was 'No module named lxml'. – LoLeRji Mar 25 '16 at 08:22
  • I found a way to do what I wanted without using the lxml package. Now I have another error, it tells me it cannot find a module named _weakref. And truly, there is no module named _weakref in python/lib directory. There is weakref.py and weakref.pyc but no _weakref.py or _weakref.pyc – LoLeRji Mar 25 '16 at 09:50
  • For pythonnet use this wiki for troubleshooting: https://github.com/denfromufa/pythonnet/wiki/Troubleshooting-FAQ – denfromufa Mar 25 '16 at 13:11
  • thanks, I'll be looking into it – LoLeRji Mar 25 '16 at 14:21
  • Unfortuantely, when I follow the tuorial for python in .NET referenced in that url and Initialize, I still get the following error: 'Unable to load DLL 'python27': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'. – LoLeRji Mar 25 '16 at 15:24
  • Did you have cpython 2.7 installed (not ironpython)? Is it in path? What happen when you type "python" in cmd? Is it 32 or 64 bit? Is your dll 32 or 64 bit or anycpu? – denfromufa Mar 25 '16 at 15:39
  • I set up my pythonpath and pythonhome environment variables, so when i type python, it opens the python terminal. It also says my installation is v 2.7.11 64 bit. I am not so sure about cpython. I am new to python so I don't know so much about it. – LoLeRji Mar 26 '16 at 19:55
  • 1
    can you open an issue on pythonnet issue tracker on github with code sample, pythonnet version, .NET version, path settings? preferable python directory should be in system `path` environment variable. cpython means the standard python (in your case 2.7.11 64 bit), not ironpython. – denfromufa Mar 27 '16 at 16:24
  • Well, by using JSON.NET instead of python, I managed to get what I was trying to do work. Thanks for all the help, I will try to get that python code to work too. But for now, I don't have much spare time, so JSON.NET is my best option – LoLeRji Mar 29 '16 at 20:27

0 Answers0