【发布时间】:2017-10-28 15:11:23
【问题描述】:
我在一个文件夹中有 30911 个 html 文件。我需要(1)检查它是否包含标签:
<strong>123</strong>
和(2)提取以下内容,直到本节结束。
但我发现一个问题是其中一些之前结束了
<strong>567</strong>
而且有些没有这个标签,在
之前结束<strong>89/strong> or others(that I do not know because I cant check 30K+files)
它在每个文件中也有不同的p p_number,有时没有id
所以我先用beautifulsoup搜索,但是不知道接下来怎么提取内容
soup = bs4.BeautifulSoup(fo, "lxml")
m = soup.find("strong", string=re.compile("123"))
顺便说一句,是否可以将内容保存为 txt 格式,但它看起来像 html 格式?
line 1
line 2
...
lin 50
如果使用 p.get_text(strip=true),那就是在一起了。
line1 content line2 content ...
line50 content....
【问题讨论】:
标签: python html parsing web-scraping beautifulsoup