问题
i need to assign a line from a text file containing 7 lines every line with a url, these urls should be replacing href url in 7 html files
the issue is that i had the same value or the same url in all html files on all seven html files here is my code:
regex = re.compile("https\:\/\/(.*)\n")
with open("urls.txt") as f:
for line in f:
result = regex.search(line)
for filename in glob.glob('/htmlz/*.html'):
with open(filename, "r") as html_file:
soup = BeautifulSoup(html_file,'html.parser')
for anchor in soup.findAll("a", attrs={ "class" : "link" }):
anchor['href'] = result.group(0)
with open(filename, "w") as htmlfile2:
htmlfile2.write(str(soup))
来源:https://stackoverflow.com/questions/59599669/assign-lines-from-txt-file-to-html-files-regex-bs4