大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全家桶1年46,售后保障稳定
#coding=utf-8
import urllib.request
from bs4 import BeautifulSoup
from urllib import error
import re
ls = ['zhenrenxiu','meinv',"lianglichemo",'rentiyishu','xiaohua']
def validateTitle(title):
rstr = r"[\/\\\:\*\?\"\<\>\|]" # '/ \ : * ? " < > |'
new_title = re.sub(rstr, "_", title) # 替换为下划线
return new_title
for j in range(1,60000):
url_origin = "http://www.7160.com/xiaohua/"+str(j)
try:
page_obj = urllib.request.urlopen(url_origin)
page_soup = BeautifulSoup(page_obj,'lxml')
total_page_obj = page_soup.find(text=re.compile('共')).string
pattern = re.compile(r'\d+')
match = pattern.search(total_page_obj)
if match == None:
total_page = 0;
else:
total_page = match.group();
for i in range(1,int(total_page)):
if i == 1 :
url = url_origin+"/index.html"
else:
url = url_origin+"/index_"+str(i)+".html"
request = urllib.request.Request(url)
try:
res = urllib.request.urlopen(request)
soup = BeautifulSoup(res,'lxml')
title_obj = soup.find(attrs={"class":"picmainer"})
if title_obj is not None:
print(url)
title = title_obj.h1.string
content = soup.find('img')
src = content.get("src")
file_name = validateTitle(title)+".jpg"
urllib.request.urlretrieve(src, "D://img2/"+file_name)
print(file_name+"保存成功")
except Exception as e:
print("异常"+str(j))
except Exception as e:
print("异常"+str(j))
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/207160.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...