吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3942|回复: 15
收起左侧

[Python 转载] emmm做一个微信公众号图片爬取的扒

  [复制链接]
cdsgg 发表于 2020-12-2 21:22
本帖最后由 cdsgg 于 2020-12-2 21:33 编辑

[Python] 纯文本查看 复制代码
读取编码: UTF-8, 大小: 2.01KB
import re
import datetime
import requests
from bs4 import BeautifulSoup
import os

a = 0

while True:



    url = input("请输入url:") 
    curr_time = datetime.datetime.now()
    print(curr_time)
    headers = {
        'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
        'cookie': 'tvfe_boss_uuid=4427f26b6d83d5d7; pgv_pvid=8192465356; pgv_pvi=2750494720; RK=cfw14pvSFY; ptcz=026939cd8bdd917551be81f3d0d2563bdb9e2d0805f4c83de8df0ea6af457e49; eas_sid=i1e690x1l8v2I68559J4e8K995; LW_sid=W1C6S0u1y8a2A6E864o8L480Z0; LW_uid=51H6V041L8i2n6Q8M4S8e4k0D0; uin_cookie=o0878530130; ied_qq=o0878530130; o_cookie=878530130; pac_uid=1_878530130; luin=o0878530130; lskey=000100000f95a236a0b3f6a309a1f6e4809612024104f9a476a9b0803995ce53ec225971d5d95f3164c7df7a; rewardsn=; wxtokenkey=777'}
    path=datetime.datetime.strftime(curr_time,'%Y%m%d%H%M')
    print(path)
    if os.path.exists(path):
        print("属于这个时间点的文件夹已经创建好")
    else:
        os.mkdir(path)
        print("创建成功!!!!正在保存图片")
    dirname=os.getcwd()+'\\'+path+'\\'
    print(dirname)
    # with open(dirname+'a.txt','w') as f:
    #     f.write(url)
    #     f.close

    req = requests.get(url=url, headers=headers).content.decode()

    soup = BeautifulSoup(req, 'lxml')

    img = soup.find_all('img')



    for i in img:
        imglist = i.get('data-src')
        print(imglist)
        pat = r"https://.*?wx_fmt=(.*)"
        rel = re.findall(pat, str(imglist))
        for j in rel:
            print(j)
            try:

                with open(dirname + '%s.%s' % (str(a),j), 'wb') as f:
                    ig = requests.get(imglist, headers=headers).content
                    f.write(ig)
                    f.close()
                    a = a + 1
            except Exception as e:
                print(e)



成品链接 蓝奏云:https://wwa.lanzouj.com/izsmEiztcaj


1.png
2.png

免费评分

参与人数 6吾爱币 +6 热心值 +5 收起 理由
马马 + 1 + 1 热心回复!
过客,, + 1 我很赞同!
luanshils + 1 + 1 我很赞同!
saltyfish + 1 + 1 我很赞同!
xiaochengzi + 1 + 1 用心讨论,共获提升!
jrzhao + 1 + 1 用心讨论,共获提升!

查看全部评分

本帖被以下淘专辑推荐:

  • · 源码|主题: 47, 订阅: 1

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

jiguanlang 发表于 2020-12-2 21:52
cdsgg 发表于 2020-12-2 21:44
可以好的 那你发给我看看

链接: https://pan.baidu.com/s/1nIeGbdx22O11uYlx-ZIHvA 提取码: cmfv 复制这段内容后打开百度网盘手机App,操作更方便哦

我只需要爬取这8列地点为山东(包括渤海海域、黄海海域)的数据,起止页码可以自己输入。保存到excel或者csv格式
 楼主| cdsgg 发表于 2020-12-2 22:01
jiguanlang 发表于 2020-12-2 21:52
链接: https://pan.baidu.com/s/1nIeGbdx22O11uYlx-ZIHvA 提取码: cmfv 复制这段内容后打开百度网盘手机A ...

要不远程吧
yzqhj 发表于 2020-12-2 21:24
jiguanlang 发表于 2020-12-2 21:36
大佬帮忙写个爬虫
 楼主| cdsgg 发表于 2020-12-2 21:37
jiguanlang 发表于 2020-12-2 21:36
大佬帮忙写个爬虫

啥样子的
jiguanlang 发表于 2020-12-2 21:40
 楼主| cdsgg 发表于 2020-12-2 21:41
jiguanlang 发表于 2020-12-2 21:40
https://www.52pojie.cn/thread-1318728-1-1.html
此悬赏贴

内网的= =咋搞
jiguanlang 发表于 2020-12-2 21:42

提供网页保存的源码可否?
 楼主| cdsgg 发表于 2020-12-2 21:44
jiguanlang 发表于 2020-12-2 21:42
提供网页保存的源码可否?

可以好的 那你发给我看看
jrzhao 发表于 2020-12-2 21:56
request建议考虑使用session,加快速度。因为微信公众号是属于同一个域名,减少连接建立断开的时间
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-15 22:23

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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