Python

Day 7

寫了個爬蟲 呵呵呵

能用啊


代碼


爬取得圖片

代碼

#coding=utf-8

import urllib

import re

def getHtml(url):

page = urllib.urlopen(url)

html = page.read()

return html

def getImg(html):

reg = r'src="(.+?\.jpg)" pic_ext'

imgre = re.compile(reg)

imglist = re.findall(imgre,html)

x = 0

for imgurl in imglist:

urllib.urlretrieve(imgurl,'%s.jpg' % x)

x+=1

html = getHtml("http://tieba.baidu.com/p/2460150866")

print getImg(html)

這樣只需要修改網址和 修改加粗部分其中后面那個pic_ext 是看網頁的位置。


通過爬蟲來學習 Python ?有什么看什么?


安裝包

http://www.tuicool.com/articles/6NVjAjr 進階版下載

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容