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

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3558|回复: 6
收起左侧

[Python 转载] 爬取王垠的博客

[复制链接]
姜蕴 发表于 2019-3-10 22:54
本帖最后由 wushaominkk 于 2019-3-11 16:33 编辑


成果下载链接:
https://pan.baidu.com/s/1acbueRlh5SFhh7OBlJL2qw 提取码: qedu


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = 'jiangwenwen'
import pdfkit
import time
import requests
from bs4 import BeautifulSoup
from fake_useragent import UserAgent

ua = UserAgent()

headers = {
    "Host": "www.yinwang.org",
    "User-Agent": ua.random,
    "Referer": "http://www.yinwang.org/",
}

# 代{过}{滤}理服务器
proxyHost = "http-dyn.abuyun.com"
proxyPort = "9020"

# 代{过}{滤}理隧道验证信息
proxyUser = "HJEG872M8LONIE4Dee"
proxyPass = "26C89049A9EE5BA9"

proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % {
  "host": proxyHost,
  "port": proxyPort,
  "user": proxyUser,
  "pass": proxyPass,
}

proxies = {
    "http": proxyMeta,
    "https": proxyMeta,
}

response = requests.get("http://www.yinwang.org/", headers=headers, proxies=proxies)
soup = BeautifulSoup(response.content, 'html.parser')
tags = soup.find_all("li", class_="list-group-item title")

for child in tags:
    start = time.time()
    url = "http://www.yinwang.org" + child.a.get('href')
    file_name = "D:\Python\资料\王垠的博客\\" + child.a.string + ".pdf"
    print("文件打印中...")
    headers["User-Agent"] = ua.random
    print("User-Agent是:{0}".format(headers["User-Agent"]))
    content = requests.get(url, headers=headers, timeout=None, proxies=proxies).text
    pdfkit.from_string(content, file_name)
    end = time.time()
    print("打印成功,本次打印耗时:%0.2f秒" % (end - start))

本帖被以下淘专辑推荐:

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

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

yoin 发表于 2019-3-11 08:41
沙发留个座,我最近也在学爬虫,加油!
nc1120917035 发表于 2019-3-11 09:26
纵横天下 发表于 2019-3-11 10:55 来自手机
Bit009 发表于 2019-9-26 10:46
博主你好,我的运行起来后,没任何报错,大约1秒后结束,但是D盘下没有文档
Bit009 发表于 2019-9-27 18:02
好像不能用啊
教授专用 发表于 2019-9-29 08:18
感谢分享 拿走一用
您需要登录后才可以回帖 登录 | 注册[Register]

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

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

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

GMT+8, 2024-5-5 16:00

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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