91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 10KB
    文件類型: .py
    金幣: 1
    下載: 0 次
    發布日期: 2021-05-13
  • 語言: Python
  • 標簽: 爬蟲??

資源簡介

學習python過程中寫的一個小說爬蟲程序,僅供學習交流

資源截圖

代碼片段和文件信息

#E小說網小說下載器
from?bs4?import?BeautifulSoup
import?requests?sys
import?threading
import?os
import?string




class?exiaoshuo(object):
????“““docstring?for?exiaoshuo“““
????def?__init__(self):
????????self.exiao?=?str(input(‘請輸入小說名字或作者的名字:‘))
????????self.server?=?‘https://www.zwda.com‘
????????self.args?=?‘https://www.zwda.com/search.php?keyword=‘
????????self.names?=?[]???#存放章節名
????????self.urls?=?[]????#存放章節鏈接
????????self.nums?=?0?????#章節數
????????self.xiao?=?[]????#存放小說章節網址
????????self.shuo?=?[]
????????self.author?=?[]???#小說作者名字
????????p?=?0

????#判斷小說是否存在
????def?get_name(self):
????????req?=?requests.get(?url?=?self.args+self.exiao)
????????html?=?req.text
????????div_bf?=?BeautifulSoup(html‘lxml‘)
????????div?=?div_bf.find_all(‘h3‘class_?=‘result-item-title?result-game-item-title‘)
????????a_bf?=?BeautifulSoup(str(div)‘lxml‘)
????????a?=?a_bf.find_all(‘a‘)
????????for?each?in?a:
????????????self.shuo.append(each.get(‘title‘))
????????????self.xiao.append(each.get(‘href‘))
????????div_2?=?div_bf.find_all(class_=“result-game-item-info“)
????????uu?=?len(div_2)
????????for?e?in?range(uu):
????????????hhh?=?BeautifulSoup(str(div_2[e])‘lxml‘)
????????????aaa?=?hhh.find(class_=“result-game-item-info-tag“)
????????????aaa?=?aaa.text.replace(‘\r‘‘‘).replace(‘\n‘‘‘).replace(‘????‘‘‘)
????????????self.author.append(aaa)



????
????def?get_urls(selftarget):
????????req?=?requests.get(url?=?target)
????????req.encoding?=?‘gbk‘
????????html?=?req.text
????????div_bf?=?BeautifulSoup(html‘lxml‘)
????????div?=?div_bf.find_all(id?=?‘list‘)
????????a_bf?=?BeautifulSoup(str(div[0])‘lxml‘)
????????a?=?a_bf.find_all(‘a‘)
????????print(a[8])
????????self.nums?=?len(a)????????????????????????????????#剔除不必要的章節,并統計章節數
????????for?each?in?a:
????????????self.names.append(each.string)
????????????self.urls.append(self.server?+?each.get(‘href‘))
????????#?print(self.names)

????def?panduan(self):
????????global?p
????????print(‘尋找如下‘)
????????for?i?in?range(len(self.shuo)):
????????????print(i+1‘《‘+self.shuo[i]+‘》‘self.author[i])
????????p?=?int(input(‘輸入下載小說序列:‘))
????????if?p?>len(self.shuo):
????????????print(‘,輸入有誤,請重新輸入‘)
????????????p?=?int(input(‘輸入下載小說序列:‘))
????????return?self.xiao[p-1]


????def?get_txt(selftarget):
????????try:
????????????req?=?requests.get(url?=?targettimeout=10)
????????????req.encoding?=?‘gbk‘
????????????html?=?req.text
????????????bf?=?BeautifulSoup(html‘lxml‘)
????????????texts?=?bf.find_all(id=“content“)
????????????texts?=?texts[0].text.replace(‘\xa0‘*4‘\n‘)
????????????return?texts
????????except:
????????????get_txt(selftarget)


????????

????def?writer(self?name?path?text):
????????write_flag?=?True
????????with?open(path?‘a‘?encoding=‘utf-8‘)?as?f:
????????????f.write(name?+?‘\n‘)
????????????f.writelines(text)
????????????f.write(‘\n\n‘)


class?xianc1(exiaoshuo):


????def?xianc(selfqqwwhh):
??????

評論

共有 條評論