Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python NotImplementedError:尝试在目录中的所有.html文件上循环不支持非相对模式_Python_Glob_Pathlib - Fatal编程技术网

Python NotImplementedError:尝试在目录中的所有.html文件上循环不支持非相对模式

Python NotImplementedError:尝试在目录中的所有.html文件上循环不支持非相对模式,python,glob,pathlib,Python,Glob,Pathlib,我试图循环遍历目录中的所有html文件,但遇到以下错误: NotImplementedError: Non-relative patterns are unsupported 我使用的代码是: from bs4 import BeautifulSoup import argparse from pathlib import Path parser = argparse.ArgumentParser(description = ("Script to scrape data from anti

我试图循环遍历目录中的所有html文件,但遇到以下错误:

NotImplementedError: Non-relative patterns are unsupported
我使用的代码是:

from bs4 import BeautifulSoup
import argparse
from pathlib import Path

parser = argparse.ArgumentParser(description = ("Script to scrape data from antismash html output"))

parser.add_argument("-p", "--path", help = "give path/to/directory containing antismash outputs", required = True)

args = parser.parse_args()

for file in Path(args.path).glob("/*.html"):
    def scraper(filename):
        soup = BeautifulSoup(open(filename), 'html.parser')
        soup.findAll('a') > os.path.basename(filename).txt

我以前使用过相同的方法,但没有出现错误,因此我不确定发生了什么。

在使用
PathLib
时,您不需要在
glob
调用中使用
/code>,正确的代码如下:

for file in Path(args.path).glob("*.html"):
    def scraper(filename):
        soup = BeautifulSoup(open(filename), 'html.parser')
        soup.findAll('a') > os.path.basename(filename).txt