python 스크립트를 실행하여 html 파일을 구문 분석하고 target="_blank"
속성을 사용하여 모든 링크 목록을 수집합니다.BeautifulSoup을 사용하여 로컬 파일에서 데이터를 수집하려고 시도했습니다
다음을 시도했지만 bs4에서 아무것도 얻지 못했습니다. SoupStrainer는 문서에서 findAll 등과 같은 방식으로 인수를 취할 것이라고 말합니다. 나는 어리석은 실수를 놓치고 있습니까?
import os
import sys
from bs4 import BeautifulSoup, SoupStrainer
from unipath import Path
def main():
ROOT = Path(os.path.realpath(__file__)).ancestor(3)
src = ROOT.child("src")
templatedir = src.child("templates")
for (dirpath, dirs, files) in os.walk(templatedir):
for path in (Path(dirpath, f) for f in files):
if path.endswith(".html"):
for link in BeautifulSoup(path, parse_only=SoupStrainer(target="_blank")):
print link
if __name__ == "__main__":
sys.exit(main())
나는 그것이 간과 한 단순한 무언가 일 것임을 알았다! 감사. –