Python爬蟲之煎蛋網圖片下載

是羅羅攀啊發表於2017-02-08

受程式設計師群的影響(自己汙的本性),他們總是帶我開車,想想我也該收集一些資料了(美女圖片)

程式碼

import requests
from lxml import etree

urls = [`http://jandan.net/ooxx/page-{}`.format(str(i)) for i in range(0,20)]
path = `C://Users/Administrator/Desktop/煎蛋網/`

header = {
    `User-Agent`:`Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36`
}

def get_photo(url):
    html = requests.get(url)
    selector = etree.HTML(html.text)
    photo_urls = selector.xpath(`//p/a[@class="view_img_link"]/@href`)
    for photo_url in photo_urls:
        data = requests.get(`http:`+photo_url,headers=header)
        fp = open(path + photo_url[-10:],`wb`)
        fp.write(data.content)
        fp.close()

for url in urls:
    get_photo(url)

我以前做個視訊,這次用不了,出錯,爬蟲只有進行時啊!!!!


相關文章