QuengC 发表于 2020-12-1 17:13:06

6666

yangminer 发表于 2020-12-1 21:31:19

看看

日暮途远Ez 发表于 2020-12-3 01:30:55

import requests
import os
import re
from bs4 import BeautifulSoup
import time


def url_open(url):
    headers = {
    'Referer': 'https://www.mzitu.com/',
    'User-Agent': 'Mozilla /5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0'
    }
    response = requests.get(url, headers=headers)
    #print(response)
    #return response
    html=response.text
    #soup=BeautifulSoup(html,'html.parser')
    soup=BeautifulSoup(html,'lxml')
    #div=soup.find('div',attrs={'id':'pins'})
    soup=soup.find(class_='postlist')
    soup1=str(soup)
    ss = r'<a href="([^"]+\d)"'
    urls=re.findall(ss,soup1)
    return urls

def url_open2(url):
    headers = {
    'Referer': 'https://www.mzitu.com/',
    'User-Agent': 'Mozilla /5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0'
    }
    response = requests.get(url, headers=headers)
    #print(response)
    #return response
    html=response.text

    return response



def save_jpg(jpg,x):
    jpg_dir='jpgs'
    filename =str(x) + '_' + jpg.split('/')[-1]
    #filename=jpg
    #x += 1
    print('正在保存文件'+filename)
    print('='*50)
    with open(filename, 'wb') as f:
      img = url_open2(jpg).content
      f.write(img)

def find_imgs(url):
    os.system("cls")
    x=0
    while True:
      headers = {
            'Referer': 'https://www.mzitu.com/',
            'User-Agent': 'Mozilla /5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0'
      }
      response = requests.get(url, headers=headers)
      html = response.text
      soup = BeautifulSoup(html, 'lxml')
      # print(html)
      soup = soup.find(class_='main-image')
      soup1 = str(soup)
      p = r'src="([^"]+\.jpg)"'
      pp = re.findall(p, soup1)
      # print(soup1)
      s = r'href="([^"]+\d)"'
      ss = re.findall(s,soup1)
      ppp=pp
      sss=ss
      print()
      print('处理图片:%s \n下一网址:%s' %(ppp,sss),)
      url=sss
      save_jpg(ppp,x)
      x+=1


def url_open1(htmls):
    print(htmls)
    for url in htmls:
      find_imgs(url)
      print('Ctrl+C退出吧。')
      time.sleep(555)



def download_new(folder='OOXX'):
    os.system('cls')
    os.system('del /qOOXX\*.*')
    os.system('rmdir OOXX')
    os.mkdir(folder)
    os.chdir(folder)
    print(url)
    htmls = url_open(url)
    htmls1 = url_open1(htmls)

if __name__ == '__main__':
    url = 'http://www.mzitu.com/'
    #download_mm()
    download_new()

不明而来的 发表于 2020-12-4 16:22:13

!!!

lzf_0763 发表于 2020-12-4 22:33:48

看看

春风醉人心 发表于 2020-12-4 23:01:16

看看

576110604 发表于 2020-12-4 23:42:11

看看

qq736723668 发表于 2020-12-5 21:47:58

学习,敬礼!

咿呀咿呀哟pyjy 发表于 2020-12-6 10:30:10

&#129312;

Lizzy_kid 发表于 2020-12-6 17:06:44

iPad 是否可以编写Python

Lizzy_kid 发表于 2020-12-6 17:07:22

水城 发表于 2013-8-23 22:43
其他平台需要的留言。

iPad Pro

赵丽颖 发表于 2020-12-11 09:15:01

good

lx520tsl 发表于 2020-12-12 15:04:10

我要手机写

轩文博 发表于 2020-12-12 19:12:44

学习学习

guo1186874557 发表于 2020-12-12 23:28:38

感谢楼主

xiangpix 发表于 2020-12-13 00:06:27

谢谢大佬。

289 发表于 2020-12-13 01:03:06

6看看

rekoe 发表于 2020-12-13 09:38:42

谢谢提供。留下了

Error° 发表于 2020-12-13 21:05:56

看看

满不懂 发表于 2020-12-13 22:16:31

新人报到进来看看
页: 251 252 253 254 255 256 257 258 259 260 [261] 262 263 264 265 266 267 268 269 270
查看完整版本: 手机上编写python