python_小爬虫

import urllib.request as request
import urllib.parse as parse
import string
print("""
+++++++++++++++++++++++
  name:cphmvp
  version: python3.3
+++++++++++++++++=++++
     """)
def baidu_tieba(url, begin_page, end_page):
    for i in range(begin_page, end_page + 1):
        sName = str(i).zfill(5)+.html
        print(正在下载第+str(i)+个页面, 并保存为+sName)
        m = request.urlopen(url+str(i)).read()
        with open(sName,wb) as file:
            file.write(m)
        file.close()
if __name__ == "__main__":
    url = "http://tieba.baidu.com/p/"
    begin_page = 1
    end_page = 3
    baidu_tieba(url, begin_page, end_page)

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。