перебрать несколько списков сверху вниз - PullRequest
0 голосов
/ 05 сентября 2018

Мне нужна помощь с итерацией по нескольким спискам с использованием выражений xpath и анализом данных на основе вхождения сверху вниз.

Я преобразовал файл PDF в файл XML, вот ссылка для PDF & XML

Я попробовал этот код на python:

from lxml import etree, html
source = open('Document 2.xml').read()

asd = html.fromstring(source.encode('utf8'))

for i in itertools.zip_longest(asd.xpath('//text[@left="54" and @font="6" and @height="28"]//b//text()'),
                       asd.xpath('//text[@left="54" and @font="10" and @height="25"]//b//text()'),
                       asd.xpath('//text[@left="54" and @font="12" and @height="18"]//b//text()'),
                       asd.xpath('//text[@left="54" and @font="0" and @height="15"]//b//preceding-sibling::text()'),
                       asd.xpath('//text[@left="54" and @font="0" and @height="15"]//b//text()')):
    print (i)

Я получил вывод как:

('Management', 'Executive Committee', 'Management', 'Managing Partner ', 'Charles P. Adams, Jr.')
('Practice Groups', 'Associates', 'Management', 'Chairman ', 'Victor H. Lott, Jr.')
('Administration', 'Claims Counsel and Loss Prevention', 'Management', 'Partner ', 'Holmes S. Adams')
('U.S. Offices', 'Clients', 'Management', 'Partner ', 'John M. Duck')
(None, 'Community Service/Pro Bono', 'Management', 'Partner ', 'William B. Gaudet')
(None, 'Financial', 'Management', 'Partner ', 'M. Ann Huckstep')
(None, 'Governance', 'Management', 'Partner ', 'Francis V. Liantonio, Jr.')
(None, 'Hiring Committee', None, 'Partner ', 'Deborah B. Rouen')
(None, 'Human Resources', None, 'Partner ', 'Charles A. Cerise, Jr.')
(None, 'Liaison Partner for Administration', None, 'Partner ', 'Martin A. Stern')
(None, 'Litigation', None, 'Liaison Partner ', 'William J. Kelly, III')
(None, 'Special Business Services', None, 'Partner ', 'Robert A. Vosbein')
(None, 'Transactions and Corporate Advisory', None, 'Partner ', 'Edward J. Rice, Jr.')
(None, 'Adams and Reese/Lange Simpson', None, 'Partner ', 'Glen M. Pilie')
(None, 'Mobile, AL Office', None, 'Partner ', 'William J. Kelly, III')
(None, 'Washington, DC Office', None, 'Partner ', 'Leslie A. Lanusse')
(None, 'Baton Rouge, LA Office', None, 'Partner ', 'James W. Young, Jr.')
(None, 'New Orleans, LA Office', None, 'Practice Group Leader ', 'Mark R. Beebe')
(None, 'Jackson, MS Office', None, 'Partner ', 'Thomas G. O’Brien')
(None, 'Houston, TX Office', None, 'Partner ', 'Stephen A. Rowe')
(None, None, None, 'Practice Group Leader ', 'Robin B. Cheatham')
(None, None, None, 'Practice Group Leader ', 'Craig G. Townsend')
(None, None, None, 'Practice Group Leader ', 'Mark W. Coffin')
(None, None, None, 'Practice Group Leader ', 'Powell G. Ogletree, Jr.')
(None, None, None, 'Chief Administrative Officer ', 'Robert M. Shofstahl')
(None, None, None, 'Chief Financial Officer ', 'Paul J. Lassalle')
(None, None, None, 'Chief Information Officer ', 'David G. Erwin, Jr.')
(None, None, None, 'Chief Marketing Officer ', 'Ann M. Wallace')
(None, None, None, 'Human Resources Director ', 'Linda Soileau')
(None, None, None, 'Purchasing Manager ', 'Morris Green')
(None, None, None, 'Recruiting Manager ', 'Ami D. Orr')
(None, None, None, 'Special Events Coordinator ', 'Teresa Lauga')
(None, None, None, 'Manager of Library Services ', 'Amy Schwarzenbach')
(None, None, None, 'Partner-in-Charge ', 'Joe A. Joseph')
(None, None, None, 'Partner-in-Charge ', 'W. David Johnson')
(None, None, None, 'Partner-in-Charge ', 'B. Jeffrey Brooks')
(None, None, None, 'Partner-in-Charge ', 'Claire Babineaux-Fontenot')
(None, None, None, 'Partner-in-Charge ', 'Edwin C. Laizer')
(None, None, None, 'Partner-in-Charge ', 'Mark C. Surprenant')
(None, None, None, 'Partner-in-Charge ', 'A. Jerry Sheldon')
(None, None, None, 'Partner-in-Charge ', 'Walter J. Cicack')

Но мне нужен такой вывод: GOOGLE_SPREADSHEET

Таким образом, в общем, я хочу, чтобы xpath выполнялся сверху вниз и ничего не возвращал между столбцами разделов, т. Е. [0,1,2], если вы увидите файл PDF, вы поймете, чего я пытаюсь достичь.

Я не уверен, смогу ли я правильно объяснить свои потребности. пожалуйста, прокомментируйте, если что-то не понятно. Если это можно сделать с помощью регулярных выражений, я тоже открыт для этого

...