I'm new to Python and BS. I have a text file where each line is in the following format. I want to extract the image urls from these lines using BS. This is just a text file and not in html format.
something something <img src="https://example.com/img1.jpg" >
something else <img src="https://example.com/img2.jpg" >
The following code doesn't do anything and just hangs; how do I fix this?
def readFile(fileName):
with open(fileName, 'r') as fp:
soup = BeautifulSoup(fp.read(),'html.parser')
images = soup.findAll('img')
print("images: ", images)
for image in images:
print (image['src'])
readFile("./imagefile.txt")