鱼C论坛

 找回密码
 立即注册
查看: 2345|回复: 0

[作品展示] 爬取起点免费作品

[复制链接]
发表于 2022-5-31 20:27:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
自己模仿别人的写的,练练手
起点中文网免费专栏爬取
使用模块:requests,re


  1. import requests
  2. import re
  3. import time


  4. url = 'https://www.qidian.com/free/all/'
  5. book_img_box = requests.get(url=url)

  6. def link_list():
  7.     list_page = requests.get(url=href)
  8.     info_page = re.findall('<h2 class="book_name"><a href="(.*?)" target="_blank" data-eid="qd_G55" data-cid=".*?" alt="(.*?)" title=".*?</a></h2>', list_page.text)
  9.     for link, title in info_page:
  10.         link = 'https:' + link
  11.         print(link, title)
  12.         #time.sleep(1)
  13.         response = requests.get(url=link)
  14.         content_data = re.findall('window.cContent = "(.*?)";', response.text, re.S)[0]
  15.         text = title + '\n' + content_data.replace('&lt;p&gt;\u3000\u3000', '') + '\n'
  16.         print(text)
  17.         with open(alt + '.txt', mode='a', encoding='utf-8') as f:
  18.             f.write(text)

  19. book_name = re.findall('<h2><a href="(.*?)".*?title=".*?">(.*?)</a></h2>', book_img_box.text)
  20. for href, alt in book_name:
  21.     href = 'https:' + href
  22.     print(href, alt)
  23.     link_list()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-29 03:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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