I am scrapping cricket test match details i have tested the results now i want to save it inside the file. while saving the html in file I am getting str object cannot be interedpreted as an integer
this is my code
for i in range(0, 2000):
url = 'http://search.espncricinfo.com/ci/content/match/search.html?search=test;all=1;page=%s' %i
html = requests.get(url)
print ('Checking page %s of 2000' %(i+1))
soupy = bs4.BeautifulSoup(html.text, 'html.parser')
time.sleep(1)
for new_host in soupy.findAll('a', {'class' : 'srchPlyrNmTxt'}):
try:
new_host = new_host['href']
except:
continue
odiurl = BASE_URL + new_host
new_host = odiurl
print(new_host)
html = requests.get(new_host).text
with open('espncricinfo-fc/{0!s}'.format(str.split(new_host, "/")[4]), "wb") as f:
f.write(html)
I am getting this error str object cannot be interedpreted as an integer
I am getting error in this line
with open('espncricinfo-fc/{0!s}'.format(str.split(new_host, "/")[4]), "wb") as f:
"wb"), but I'm guessing you're trying to writestrdata rather thanbytes. What happens if you changerequests.get(new_host).texttorequests.get(new_host).text.encode()?