pdfquery/PyQuery:示例代码没有显示 AttributeError 但我的有……为什么?
pdfquery/PyQuery: example code shows no AttributeError but mine does...why?
我正在按照 here. The author has some documentation 找到的示例代码进行操作,他在其中列出了用于编写程序的一些步骤。当我 运行 将整个程序组合在一起时,它 运行 非常完美,但是当我按照他提出的步骤进行操作时,我得到了一个 AttributeError。
这是我的代码
pdf = pdfquery.PDFQuery("Aberdeen_2015_1735t.pdf")
pdf.load()
pdf.tree.write("test3.xml", pretty_print=True, encoding="utf-8")
sept = pdf.pq('LTPage[pageid=\'1\'] LTTextLineHorizontal:contains("SEPTEMBER")')
print(sept.text())
x = float(sept.get('x0'))
y = float(sept.get('y0'))
cells = pdf.extract( [
('with_parent','LTPage[pageid=\'1\']'),
('cells', 'LTTextLineHorizontal:in_bbox("%s,%s,%s,%s")' % (x, y, x+600, y+20))
])
一切 运行 都很好,直到它到达 "sept.get" 那里说“'PyQuery' 对象没有属性 'get'”。有谁知道为什么程序在 运行 在一起时不会遇到此错误,但当一段代码为 运行 时会发生此错误?
根据 PyQuery API reference,PyQuery
对象确实没有 get
成员。代码示例必须已过时。
根据 https://pypi.python.org/pypi/pdfquery,使用 .attr
检索属性:
x = float(sept.attr('x0'))
根据 history of pyquery
's README.rst
判断,get
从未被记录在案,只是由于某些副作用(可能是某些委托给 dict
)才起作用。
我正在按照 here. The author has some documentation 找到的示例代码进行操作,他在其中列出了用于编写程序的一些步骤。当我 运行 将整个程序组合在一起时,它 运行 非常完美,但是当我按照他提出的步骤进行操作时,我得到了一个 AttributeError。
这是我的代码
pdf = pdfquery.PDFQuery("Aberdeen_2015_1735t.pdf")
pdf.load()
pdf.tree.write("test3.xml", pretty_print=True, encoding="utf-8")
sept = pdf.pq('LTPage[pageid=\'1\'] LTTextLineHorizontal:contains("SEPTEMBER")')
print(sept.text())
x = float(sept.get('x0'))
y = float(sept.get('y0'))
cells = pdf.extract( [
('with_parent','LTPage[pageid=\'1\']'),
('cells', 'LTTextLineHorizontal:in_bbox("%s,%s,%s,%s")' % (x, y, x+600, y+20))
])
一切 运行 都很好,直到它到达 "sept.get" 那里说“'PyQuery' 对象没有属性 'get'”。有谁知道为什么程序在 运行 在一起时不会遇到此错误,但当一段代码为 运行 时会发生此错误?
根据 PyQuery API reference,PyQuery
对象确实没有 get
成员。代码示例必须已过时。
根据 https://pypi.python.org/pypi/pdfquery,使用 .attr
检索属性:
x = float(sept.attr('x0'))
根据 history of pyquery
's README.rst
判断,get
从未被记录在案,只是由于某些副作用(可能是某些委托给 dict
)才起作用。