'NotImplementedError: Non-relative patterns are unsupported from attempted looping over all .html files in a directory
I am trying to loop over all html files in a directory but am getting this error:
NotImplementedError: Non-relative patterns are unsupported
The code I am using is:
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
I have previously used the same method and not gotten an error so I am not sure what is going on.
Solution 1:[1]
You don't need to use /
inside the glob
call when working with PathLib
. The correct code would be:
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |