import requests
import os
shows=[]
page=str(requests.get("http://dramaonline.com").text.encode('ascii','ignore'))
for item in page.split("\n"):
	if "title=" in item:
		print ("Title tag in item {0}".format(item))
		if "<a href=" in item:
			print ("<a href= found")
			episodepage=item.split('<a href="')[1].split('"')[0]
			print "Episode page is {0}".format(episodepage)
			episodename=item.split('title="')[1].split('"')[0]
			print "Searching for vidrail link in {0}".format(episodename)
			for line in str(requests.get(episodepage).text.encode('ascii','ignore')).split("\n"):
				if "vidrail" in line:
					print line
				if 'src="http://www.vidrail' in line:
					print "Vidrail link found in line {0}".format(line)
					vidraillink=line.split('src="')[1].split('"')[0]
					print "Vidrail link is {0}".format(vidraillink)
					for line in str(requests.get(vidraillink).text).encode('ascii','utf8').split("\n"):
						if ".mp4" in line:
							print ".mp4 found in line {0}".format(line)
							episodelink=line.split('src="')[1].split('"')[0]
							print "Episode link is {0}".format(episodelink)
							shows.append({episodename,episodelink})
f=open("shows.txt",'w')
f.write(str(shows))
f.close()