首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >'str' object cannot be interpreted as an integer?

'str' object cannot be interpreted as an integer?

提问于 2023-09-26 15:08:49
回答 0关注 0查看 118

import urllib.request import re url="https://cn.chinadaily.com.cn/" count = 0 def download(src): global count try: resp =urllib.request.urlopen(src) data = resp.read() p = src.rfind("/") fileName=src[p+1:] fobj = open("download\\"+fileName,"wb") fobj.write(data) fobj.close() print("downloaded",fileName) count = count+1 except Exception as err: print(err) def getHtml(): html = "" try: resp = urllib.request.urlopen(url) data = resp.read() html = data.decode() except Exception as err: print(err) return html try: html = getHtml().lower() reg = r"<img.+src\s*=\s*" m = re.search(reg,html) while m: a = m.end() s = html[a:] m = re.search(r">",s) if m: b = m.start() html = s[m.end():] s = s[:b] m.re.search(r"[\',\"][a-z,0-9,\.,-,_,/]+(.jpg|.png|.jpeg)[\',\"]",s) if m: src =s[1:m.end()-1] src = urllib.request.urljion(url,src) print(src) download(src) m = re.search(reg,html) print("total",count,"images") except Exception as err: print(err)

'str' object cannot be interpreted as an integer

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档