python3,切图片

切图片:
import contextlib
from urllib import request

with   contextlib.closing(request.urlopen( " http://mm.taobao.com/json/request_top_list.htm?type=2&page=4 " )) as front_page:
    for line in front_page:
        index1 = str (line).find( '<img src="' )  # 查找
        if index1 > 0 :                  #  如果能找到,进行分割
        list1 = str (line).split( '<img src="' )[ 1 ]   # 使用split进行分割,,结果是一个列表,列表中有两部分,现在取的是第二部分
        list2 = list1.split( '" alt="" width="' )[ 0 ]
        print (list2)

猜你喜欢

转载自blog.csdn.net/it_zxl001/article/details/79776777