我在安装lxml时遇到问题。 我已经尝试过在这个网站和其他网站的相关问题的解决scheme,但不能解决问题。 需要一些build议/解决这个问题。 我在执行pip install lxml后提供完整的日志, Downloading/unpacking lxml Downloading lxml-3.3.5.tar.gz (3.5MB): 3.5MB downloaded Running setup.py (path:/tmp/pip_build_root/lxml/setup.py) egg_info for package lxml /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url' warnings.warn(msg) Building lxml version 3.3.5. Building without Cython. Using build configuration of libxslt 1.1.28 warning: no previously-included files found matching '*.py' Installing collected packages: lxml Running setup.py install for […]
我正在运行下列命令来安装包中的文件“ pip install -r requirements.txt –download-cache=~/tmp/pip-cache ”。 requirements.txt包含像pacakages # Data formats # ———— PIL==1.1.7 # html5lib==0.90 httplib2==0.7.4 lxml==2.3.1 # Documentation # ————- Sphinx==1.1 docutils==0.8.1 # Testing # ——- behave==1.1.0 dingus==0.3.2 django-testscenarios==0.7.2 mechanize==0.2.5 mock==0.7.2 testscenarios==0.2 testtools==0.9.14 wsgi_intercept==0.5.1 而要安装“lxml”包,我得到以下的错误 Requirement already satisfied (use –upgrade to upgrade): django-testproject>=0.1.1 in /usr/lib/python2.7/site-packages/django_testproject-0.1.1-py2.7.egg (from django-testscenarios==0.7.2->-r requirements.txt (line 33)) Installing collected packages: […]
我已经把我的脚本从python 2.7转换为3.2,并且有一些bug。 # -*- coding: utf-8 -*- import time from datetime import date from lxml import etree from collections import OrderedDict # Create the root element page = etree.Element('results') # Make a new document tree doc = etree.ElementTree(page) # Add the subelements pageElement = etree.SubElement(page, 'Country',Tim = 'Now', name='Germany', AnotherParameter = 'Bye', Code='DE', Storage='Basic') pageElement […]
我想安装Lxml,所以我可以安装Scrapy。 当我今天更新我的Mac时,不会让我重新安装lxml,我得到以下错误: In file included from src/lxml/lxml.etree.c:314: /private/tmp/pip_build_root/lxml/src/lxml/includes/etree_defs.h:9:10: fatal error: 'libxml/xmlversion.h' file not found #include "libxml/xmlversion.h" ^ 1 error generated. error: command 'cc' failed with exit status 1 我已经尝试使用brew来安装libxml2和libxslt,两者都安装正常,但我仍然无法安装lxml。 上次我正在安装我需要启用Xcode的开发工具,但自从它更新到Xcode 5,它不再给我这个选项。 有谁知道我需要做什么?
我想写一个代码片段,它会抓取下面所有三个实例中包含代码标签的<content>标签中的所有文本,包括lxml。 我试过tostring(getchildren())但会错过标签之间的文本。 我没有太多的运气searchAPI的相关function。 你能帮我吗? <!–1–> <content> <div>Text inside tag</div> </content> #should return "<div>Text inside tag</div> <!–2–> <content> Text with no tag </content> #should return "Text with no tag" <!–3–> <content> Text outside tag <div>Text inside tag</div> </content> #should return "Text outside tag <div>Text inside tag</div>"
我有一个XML文档,我正试图使用Etree.lxmlparsing <Envelope xmlns="http://www.example.com/zzz/yyy"> <Header> <Version>1</Version> </Header> <Body> some stuff <Body> <Envelope> 我的代码是: path = "path to xml file" from lxml import etree as ET parser = ET.XMLParser(ns_clean=True) dom = ET.parse(path, parser) dom.getroot() 当我试图得到dom.getroot()时,我得到: <Element {http://www.example.com/zzz/yyy}Envelope at 28adacac> 但是我只想要: <Element Envelope at 28adacac> 当我这样做 dom.getroot().find("Body") 我没有得到任何回报。 但是,当我 dom.getroot().find("{http://www.example.com/zzz/yyy}Body") 我得到了一个结果。 我认为通过ns_clean =真parsing器会阻止这一点。 有任何想法吗?
我有一个HTML文件(来自Newegg),他们的HTML组织如下。 规格表中的所有数据都是“ desc ”,而每个部分的标题都是“ 名称”。 以下是来自Newegg页面的两个数据示例。 <tr> <td class="name">Brand</td> <td class="desc">Intel</td> </tr> <tr> <td class="name">Series</td> <td class="desc">Core i5</td> </tr> <tr> <td class="name">Cores</td> <td class="desc">4</td> </tr> <tr> <td class="name">Socket</td> <td class="desc">LGA 1156</td> <tr> <td class="name">Brand</td> <td class="desc">AMD</td> </tr> <tr> <td class="name">Series</td> <td class="desc">Phenom II X4</td> </tr> <tr> <td class="name">Cores</td> <td class="desc">4</td> </tr> <tr> <td class="name">Socket</td> <td […]
我正在尝试在Windows 64位机器上为Python 2.7构buildlxml。 我找不到Python 2.7版本的lxml egg。 所以我正在从源头上编译它。 我正在按照这个网站上的说明 http://lxml.de/build.html 在静态链接部分。 我收到错误 C:\Documents and Settings\Administrator\Desktop\lxmlpackage\lxml-2.2.6\lxml-2.2. 6>python setup.py bdist_wininst –static Building lxml version 2.2.6. NOTE: Trying to build without Cython, pre-generated 'src/lxml/lxml.etree.c' need s to be available. ERROR: 'xslt-config' is not recognized as an internal or external command, operable program or batch file. ** make sure the […]
我有以下function,它将XML文件parsing为字典粗略的工作。 不幸的是,由于Python字典没有sorting,所以我无法按照我的意愿循环访问节点。 我该如何改变它,所以它输出一个有序的字典,它反映了当用'for'循环时节点的原始顺序。 def simplexml_load_file(file): import collections from lxml import etree tree = etree.parse(file) root = tree.getroot() def xml_to_item(el): item = None if el.text: item = el.text child_dicts = collections.defaultdict(list) for child in el.getchildren(): child_dicts[child.tag].append(xml_to_item(child)) return dict(child_dicts) or item def xml_to_dict(el): return {el.tag: xml_to_item(el)} return xml_to_dict(root) x = simplexml_load_file('routines/test.xml') print x for y in x['root']: […]
这是我的错误: (mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install lxml Downloading/unpacking lxml Running setup.py egg_info for package lxml Building lxml version 2.3. Building without Cython. ERROR: /bin/sh: xslt-config: not found ** make sure the development packages of libxml2 and libxslt are installed ** Using build configuration of libxslt Installing collected packages: lxml Running setup.py install for lxml Building lxml version […]