python抓取百度首页
程序员文章站
2022-06-20 23:45:50
import urllib
def downurl(url,filename):
try:
&nbs...
import urllib
def downurl(url,filename):
try:
fp=urllib.urlopen(url)
except:
print('download error')
return 0
op=open(filename,'wb')
while 1:
s=fp.read()
if not s:
break
op.write(s)
fp.close()
op.close()
return 1
downurl("https://www.baidu.com","d:\\code\\url.txt")
def downurl(url,filename):
try:
fp=urllib.urlopen(url)
except:
print('download error')
return 0
op=open(filename,'wb')
while 1:
s=fp.read()
if not s:
break
op.write(s)
fp.close()
op.close()
return 1
downurl("https://www.baidu.com","d:\\code\\url.txt")
上一篇: 用PDB库调试Python程序