lxml.pdf - Python Library lxml INF 55x Wensheng Wu 1 Extraction using Python library lxml \u2022 lxml should be installed by default in your Amazon EC2 AMI

lxml.pdf - Python Library lxml INF 55x Wensheng Wu 1...

This preview shows page 1 - 13 out of 13 pages.

Python Library: lxml INF 55x Wensheng Wu 1
Image of page 1
Extraction using Python library lxml lxml should be installed by default in your Amazon EC2 AMI Linux instance If not sudo pip install lxml (this is for python 2) sudo python3 -m pip install lxml (python 3) If you are using Cygwin First install libxml2, libxslt (see next slide) Then "pip install lxml" 2
Image of page 2
Cygwin 3 Install libxml2 and libxml2-devel
Image of page 3
Cygwin 4 Install libxslt and libxslt-devel
Image of page 4
5
Image of page 5
Example from lxml import etree f = open('bibs.xml') tree = etree.parse(f) print(etree.tostring(tree, pretty_print=True)) 6
Image of page 6
Example for element in tree.xpath("//author"): print(etree.tostring(element)) <author>Serge Abiteboul</author> <author><first-name>Rick</first-name><last-name>Hull</last-name></author> <author age="20">Victor Vianu</author> <author>Jeffrey D. Ullman</author> <author/> 7
Image of page 7
Example for element in tree.xpath("//author"):
Image of page 8
Image of page 9
Image of page 10
Image of page 11
Image of page 12
Image of page 13

You've reached the end of your free preview.

Want to read all 13 pages?

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes