I have a file "BatchLink.txt" which contains urls in new lines.I want to read these lines by lines and pass the argument linewise to a batch script.
Let's say, my batchlink.txt contains this data :-
http://link1
http://link2
http://link3
http://link4
Now, I want to read linewise and send this to a batch file one line at a time.This question is the continuation of my previous question Here. Right Now, I have this code :-
import requests
from bs4 import BeautifulSoup
import subprocess
file = open("BatchLinks.txt", "w")
r = requests.get('http://www.crunchyroll.com/i-cant-understand-what-my-husband-is-saying')
soup = BeautifulSoup(r.text)
print soup.title
subtitles = soup.findAll('div',{'class':'wrapper container-shadow hover-classes'})
for episode in subtitles:
x = episode.find_all('a')
for a in x:
#print a['href']
z = a['href']
l = 'http://www.crunchyroll.com'+ z
print l
file.write(l+'\n')
print '-----------------------------------------------------------------------------'
file.close()
file = open('BatchLinks.txt', "r")
lines = file.readlines()
print lines
if __name__ =="__main__":
response = lines
print(lines)
p = subprocess.Popen("_start.bat", stdin = subprocess.PIPE)
time.sleep(1)
p.stdin.write(response) #Answer the question
time.sleep(20)
But, right now, the problem is that it reads the lines simultaneosuly and send it to the batch file.Which returns me the output []
. I can't seem to get it work.Any help/guidance would be appreciated.