I am scraping images from https://www.open2study.com/courses I got all the image sources but dont know how to display the images (instead of links) on a table with 2 column ( one column for title and one for image) on a html file.Can expert help me out?
import urllib
from bs4 import BeautifulSouptitles = []
images = []r = urllib.urlopen('https://www.open2study.com/courses').read()
soup = BeautifulSoup(r)for i in soup.find_all('div', {'class': "courses_adblock_rollover"}):titles.append(i.h2.text)for i in soup.find_all('img', {'class': "image-style-course-logo-subjects-block"}):images.append(i.get('src'))with open('test.txt', "w") as f:for i in zip(titles, images):f.write(i[0].encode('ascii', 'ignore') +'\n'+i[1].encode('ascii', 'ignore') +'\n\n')header = '<!doctyle html><html><head><title>My Title</title></head><body>'
body = '<table><thead><tr><th></th><th></th></tr>'footer = '</table></body></html>'
img_tag = '<img src=,{}">'with open('test.txt', 'r') as input, open('test.html', 'w') as output:output.write(header)output.write(body)for line in input:col1 = line.rstrip().split()col2 = line.rstrip().split()output.write('<tr><td>{}</td><td>{}</td></tr>\n'.format(col1, col2))output.write(footer)