<commit_before># -*- coding:utf-8 -*-
from lxml import etree
import requests

__author__ = 'monkey'

# 题目要求：
# 用Pyhton写一个爬图片的程序，爬这个链接里的日本妹子图片
# 地址：http://tieba.baidu.com/p/2166231880

def spider(url):
    html = requests.get(url)
    selector = etree.HTML(html.text)
    picitems = []
    picitems = selector.xpath('//div[@id="post_content_29397251028"]')

    print(len(picitems))

if __name__ == '__main__':
    url = "http://tieba.baidu.com/p/2166231880"
    spider(url)<commit_msg>第0013题<commit_after># -*- coding:utf-8 -*-
from lxml import etree
import requests
import urllib

__author__ = 'monkey'

# 题目要求：
# 用Pyhton写一个爬图片的程序，爬这个链接里的日本妹子图片
# 地址：http://tieba.baidu.com/p/2166231880

# 获取url地址，对页面进行爬去
def spider(url):
    html = requests.get(url)
    selector = etree.HTML(html.text)
    picitems = []
    picitems = selector.xpath('//div[@id="post_content_29397251028"]/img[@class="BDE_Image"]')
    print(len(picitems));

    i = 0
    for pic in picitems:
        url = pic.xpath('@src')[0]
        print(url)
        dir = './%d.jpg'%i
        download_Image(url, dir)
        i += 1



def download_Image(url, save_path):
    urllib.request.urlretrieve(url, save_path)


if __name__ == '__main__':
    url = "http://tieba.baidu.com/p/2166231880"
    spider(url)
{'fraction_non_alphanumeric': 0.15814319433516916, 'fraction_numerical': 0.05586152635719906, 'mean_word_length': 3.4475524475524475, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3905795', 'n_tokens_mistral': 611, 'n_tokens_neox': 576, 'n_words': 80}