爬取煎蛋网妹子图片

import requests
import bs4
import base64
import urllib.request
num_photo = 1
def download_photo(url , num ):
  global num_photo
  response = urllib.request.urlopen(url)
  cat = response.read()
  with open( 'I:/a/' + num + '.jpg' , 'wb') as f :
      f.write(cat)
  a = num_photo
  print("当前已下载第%d张" % a)

  num_photo = num_photo + 1 
  
def get_url(url): # 下载这个网页
    headers = { "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.6735.400 QQBrowser/10.2.2614.400" }
    res = requests.get(url , headers = headers)
    return res
def get_soup(res):
    soup = bs4.BeautifulSoup(res.text , "html.parser")
    return soup

def get_page(num):
    
   # url = input("请输入一个url:")
    url = "http://jandan.net/ooxx/page-" + str(num) + "#comments"
    large_url = "http://wx2.sinaimg.cn/large/"
    res = get_url(url)
   # with open("date.txt","w" , encoding ='utf-8') as file:
   #         file.write(res.text)
   # print(res.text)
    soup = get_soup(res)
    num = 0 
    for i in soup.select('.img-hash'):
        #print(i.text)
        num = num + 1 
        link = base64.b64decode(i.text.encode('utf-8'))
       # print(link)
        B_link = str(link , 'utf-8').split('/')[-1]
        #去找到他的哈希码
        #print(B_link)
        New_url = large_url + B_link
        #print(New_url)
        download_photo(New_url , B_link , )
def main():
   print("you should input tow number to request download some picture what you like:")
   num = input("请输入要下载煎蛋网妹子图的页数:(当前输入第一个数字)")
   num1 = input("请输入要下载煎蛋网妹子图的页数:(当前输入第二个数字)")
   for each in range(int(num) , int(num1)):
       get_page(each)
   print("下载完成!")
if __name__ == "__main__":
   main()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值