1.開發(fā)環(huán)境python2.7
2.爬取貼吧頁面代碼實現(xiàn)
# -*- coding:utf-8 -*-
"""
爬取python貼吧網(wǎng)頁
"""
# 引入需要的模塊
import urllib2
# python吧第一頁的url地址
url = "http://tieba.baidu.com/f?kw=download_file&ie=utf-8&pn=0 "
# 獲取
response = urllib2.urlopen(url)
# 將獲取到的內(nèi)容賦值給content變量
content = response.read()
print content
with open("python_1.html", "w") as f:
f.write(content)