当前位置:Gxlcms > Python > 使用Python访问并下载网页内容

使用Python访问并下载网页内容

时间:2021-07-01 10:21:17 帮助过:121人阅读

[Python]代码

  1. #!/usr/local/bin/python3.2
  2. import urllib.request,io,os,sys
  3. req = urllib.request.Request("http://www.google.com")
  4. f = urllib.request.urlopen(req)
  5. s = f.read()
  6. s = s.decode('gbk','ignore')
  7. mdir = sys.path[0]+'/'
  8. file = open(mdir+'admin6.txt','a',1,'gbk')
  9. file.write(s)
  10. file.close()

人气教程排行