gawel / pyquery

A jquery-like library for python
http://pyquery.rtfd.org/
Other
2.3k stars 182 forks source link

map does not support python3 #130

Closed lufeihaidao closed 8 years ago

lufeihaidao commented 8 years ago
  File "src/lxml/lxml.etree.pyx", line 3350, in lxml.etree.tostring (src/lxml/lxml.etree.c:79228)
TypeError: Type 'str' cannot be serialized.

I got this error when I try to copy https://pythonhosted.org/pyquery/_modules/pyquery/pyquery.html#PyQuery.map example

d('p').map(lambda i, e: PyQuery(e).text())
# ['Hi there', 'Bye']
gawel commented 8 years ago

Works for me:

Python 3.5.1 (default, Jan  7 2016, 16:14:40) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyquery import PyQuery
>>> d = PyQuery('<p class="hello">Hi there</p><p>Bye</p><br />')
>>> d('p').map(lambda i, e: PyQuery(e).text())
['Hi there', 'Bye']
>>> 
lufeihaidao commented 8 years ago

Oh sorry maybe it's my fault. I cannot understand why I get different results from the same code ...

gawel commented 8 years ago

Try to report exact versions of python, pyquery and lxml