Python 在从pdf转换的html文件上使用path和beautiful soup

Python 在从pdf转换的html文件上使用path和beautiful soup,python,html,xpath,web-scraping,beautifulsoup,Python,Html,Xpath,Web Scraping,Beautifulsoup,我使用python中名为“pdfminer”的包将pdf文件转换为html文件。我想从pdf文件中获取有用的信息。如何在任何html文件上使用xpath和Beautil。我知道如何在网页上使用xpath和beautiful soup,给出如下链接: # get tree def get_tree(url): r = requests.get(url) tree = html.fromstring(r.content) return tree # get soup def

我使用python中名为“pdfminer”的包将pdf文件转换为html文件。我想从pdf文件中获取有用的信息。如何在任何html文件上使用xpath和Beautil。我知道如何在网页上使用xpath和beautiful soup,给出如下链接:

# get tree
def get_tree(url):
    r = requests.get(url)
    tree = html.fromstring(r.content)
    return tree

# get soup
def get_soup(url):
    r = requests.get(url)
    data = r.text
    soup = BeautifulSoup(data)
    return soup
如果只提供html文件,谁能给我一些关于如何使用xpath和BeautifulSoup的例子?
谢谢

最终,我通过深入API和谷歌搜索找到了解决方案。以下是在使用beautifulsoup和xpath之前,仅通过给定的html文件作为输入获取soup或tree的方法:

soup = BeautifulSoup(open("output.html"))
doc = open("output.html", "r").read()
tree = etree.HTML(doc)

然后,您可以使用soup或tree从html文件中提取所需的内容。

您不能使用
xpath
使用
BeautifulSoup
html解析器。考虑使用。除此之外,你的问题太宽泛了。请尽量说得更具体些。@alecxe我想我的问题是明确的。我刚刚找到了一种使用BeautifulSoup的方法,但对xpath一无所知。一定有某种方法可以使用xpath。具体地说,我的意思是,如果您提供一个HTML代码并记录您试图从中获取的数据,会更好。CSS选择器非常强大,可以完全代替xpath使用。此外,如果您只是询问
xpath
BeautifulSoup
-这是的副本。@alecx请查看我的解决方案。