Using python I am trying to get the whole html code of a target CSS selector. The target html code looks like following and I want this whole code:
<img class="card-img-top" src="/svg/2798804.svg" width="200px" height="200px" alt="kitten animal cat " style="user-select: auto;">
My python code :
with open("links.txt", "r") as a_file:
for line in a_file:
stripped_line = line.strip()
endpoint = stripped_line
start = stripped_line.find('/tag/') + 5
end = stripped_line.find('.html', start)
filename = stripped_line[start:end]
soup = BeautifulSoup(requests.get(endpoint).text)
completeName = os.path.join(workingpath, filename + ".txt")
with open(completeName, "w") as f_out:
for inp in soup.select('.card-img-top'):
print(inp["value"], file=f_out)
Getting this error when running the code:
KeyError: 'value'
<img>to be an<input>?