|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
2020.12.30,23:18
真正0基础学了45天到这儿,煎蛋网代码变了好多,网址需要解码,尝试了一下
import部分我也不知道2、3两个用不用,反正写上了……
import urllib.request
import urllib.parse
import json
import time as t
import base64
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):
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 = 'http://jandan.net/ooxx/'+ temp +'#comments'
#print(page_url) #测试
return page_url
def mm_page_url(page_url):
mm_page_urls = []
html = open_url(page_url)
html = html.decode('utf-8')
a = html.find('img src=')
while a != -1:
b = html.find('.jpg',a,a+100) #页面中图片地址字符长度57,小于100
if b != -1:
temp = 'http:'+ html[(a+9):(b+4)]
#print(temp) #测试
mm_page_urls.append(temp)
else:
break #小甲鱼用b = a+9
a = html.find('img src=',b)
#print(mm_page_urls[0]) #测试
return mm_page_urls
def mm_download(page):
global num
#page_urls = 'start'
page_urls = page_url(page)
#mm_page_url = []
mm_page_url_out = mm_page_url(page_urls)
for each in mm_page_url_out:
mm_img = open_url(each)
with open('C:\\Users\\imcaimimi\\Desktop\\python learning\\mm\\mm_%s.jpg' % (num),'wb') as f:
f.write(mm_img)
num +=1
t.sleep(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)
|
|