鱼C论坛

 找回密码
 立即注册
查看: 2246|回复: 0

[作品展示] 爬虫8-OOXX爬妹子图-正则表达式修改

[复制链接]
发表于 2021-1-3 21:39:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import urllib.request
import time as t
import base64
import re

def open_url(url_in):
    req = urllib.request.Request(url_in)
    req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66')
    response = urllib.request.urlopen(req)
    html_out = response.read()
    return html_out


def page_url(page):#页面地址base64解码
    page_str = str(t.localtime().tm_year) + str(t.localtime().tm_mon) + str(t.localtime().tm_mday)+'-'+str(page)
    temp = str(base64.b64encode(str.encode(page_str)))
    temp = temp[2:len(temp)-1]
    page_url_out = 'http://jandan.net/ooxx/'+ temp +'#comments'
    #print(page_url) #测试
    return page_url_out

def mm_page_url(page_url_in):
    html = open_url(page_url_in)
    html = html.decode('utf-8')
    mm_pattern = re.compile(r'<a href="([^"]+\.jpg)')
    #mm_pattern = re.compile(r'<a href="//(.+\.jpg)')错误会执行到后一个.jpg
    mm_page_urls_out = mm_pattern.findall(html)
    return mm_page_urls_out

'''
    for each in mm_page_urls_out:
        print(each) #测试'''

def mm_download(page):
    global num
    page_urls = page_url(page)
    mm_page_urls = mm_page_url(page_urls)
    for each in mm_page_urls:
        filename = 'C:\\Users\\imcaimimi\\Desktop\\python learning\\mm\\mm_%s.jpg' % (num)
        urllib.request.urlretrieve(('http:'+each),filename,None)
        num += 1
        
n = int(input('Confirm the pages of mm_pics_jiandansuishoupai:'))
html = open_url('http://jandan.net/ooxx')
html = html.decode('utf-8')
ini_a = html.find('current-comment-page')
ini_b = html.find(']',ini_a)
ini_page = int(html[ini_a+23:ini_b])
#print(ini_page)#测试
num = 0
for i in range(n):
    mm_download(ini_page-i)

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-16 21:15

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表