经过 3 个小时的研究,我能够从数据创建一个可解析的 XML 文档。不幸的是,我未能成功地整理出一套完全可重复使用的步骤,以便我在未来的拍卖出版物中使用。
顺便说一句,我确实尝试打电话询问洛杉矶县是否可以提供拍卖房产的替代格式(excel 等),但答案是否定的。这就是你的政府。
这是我的方法的高级视图:
- 使用以下命令将 PDF 转换为文本文件Poppler http://poppler.freedesktop.org/
- 使用 RegEx foo 从数据中清理并创建 XML 节点
- 使用 XML 美化器/验证器来查找错误并进行清理
- 使用Python/ruby添加Google Maps Link节点,并链接到LA County Assessors Map(http://assessormap.co.la.ca.us/mapping/rolldata.asp?ain=APN-GOES_HERE http://assessormap.co.la.ca.us/mapping/rolldata.asp?ain=APN-GOES_HERE) and
- 使用 Ruby 将 XML 转换为 CSV
I used http://xmlbeautifier.com/ http://xmlbeautifier.com/作为我的 XML 美化器/验证器,因为它速度快并且提供准确的错误报告,包括行号。
Use Homebrew http://brew.sh/Mac 版 Poppler 安装:
brew install poppler
安装 Poppler 后,您应该可以访问 pdftotext 实用程序来转换 PDF:
pdftotext -layout -f 24 -l 687 AuctionBook2013.pdf auction_book.txt
这是 XML 的预览(单击此处获取完整的 XML http://xml.nopaste.dk/p58862):
<?xml version="1.0" encoding="UTF-8"?>
<listings>
<item id="1">
<nsb>536</nsb>
<minbid>3,422</minbid>
<apn>2006 003 001</apn>
<delinquent_year>03</delinquent_year>
<apn_old>2006 003 001</apn_old>
<description>LICENSED SURVEYOR'S MAP
AS PER BK 25 PG 28 OF L S LOT 1
BLK 1 ASSESSED TO J AND S
LIMITED LLC C/O DUNA CSARDAS -
JULIUS JANCSO LOCATION COUNTY OF
LOS ANGELES</description>
<address>VACANT LOT</address>
</item>
编辑:添加我编写的 Ruby 将 XML 转换为 CSV。
require 'rexml/document'
require 'CSV'
class Auction
def initialize
f = File.new('AuctionBook2013.xml', 'r')
doc = REXML::Document.new(f)
CSV.open("auction.csv", "w+b") do |csv|
csv << ['id', 'minbid', 'apn', 'delinquent_year', 'apn_old', 'description', 'address']
doc.elements.each('/listings/item') do |item|
csv << [item.attributes['id'],
item.elements['minbid'].text,
item.elements['apn'].text,
item.elements['delinquent_year'].text,
item.elements['apn_old'].text,
item.elements['description'].text,
item.elements['address'].text]
end
end
end
end
a = Auction.new()
链接到最终 CSV http://nopaste.dk/p58958