我正在废弃板球比赛的详细信息,现在我已经测试了结果,我想将其保存在文件中。在将html保存到文件中时,我得到了str object cannot be interedpreted as an integer
这是我的代码
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)
我收到此错误str object cannot be interedpreted as an integer
此行出现错误
,以open('espncricinfo-fc / {0!s}'。format(str.split(new_host,“ /”)[4]),“ wb”)as f: < / p>
答案 0 :(得分:1)
如果您使用的是Python 3.x,请尝试将最后一行更改为
new_host = str(new_host['href'])
也可以尝试一下
[root@ip-10-0-1-13]# kubectl config current-context
kubernetes-admin@kubernetes
答案 1 :(得分:0)
问题是您的print
语句。
它应该显示为
print('checking %d etc.' % (i + 1))