【发布时间】:2022-11-28 11:04:12
【问题描述】:
我编写了使用 Beautiful Soup 提取非常大的站点地图 xml 文件 (10mb) 的 URL 的代码,它完全按照我想要的方式工作,但它似乎只处理了整个文件的一小部分。这是我的代码:
`sitemap = "sitemap1.xml"
from bs4 import BeautifulSoup as bs
import lxml
content = []
with open(sitemap, "r") as file:
# Read each line in the file, readlines() returns a list of lines
content = file.readlines()
# Combine the lines in the list into a string
content = "".join(content)
bs_content = bs(content, "xml")
result = bs_content.find_all("loc")
for result in result:
print(result.text)
`
我已经更改了我的 IDE 以允许更大的文件,它似乎只是在 XML 文件末尾的随机点开始该过程,并且只从那里提取。
【问题讨论】:
标签: python-3.x xml beautifulsoup sitemap