每日早上8:30執行
30 8 * * * source /home/topgrec/source/ddlbook.sh &
#! /bin/bash
python /home/topgrec/source/python/downloadbooks.py
downloadbooks.py
):來源網站:筆趣網
書名:透視醫圣 豪婿
import os
import re
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36'
}def getdetails(info):titlename = info.textlinkurl = rooturl + info.get('href')bookcontent = requests.get(linkurl, headers = headers).content.decode('gbk')mysoup = BeautifulSoup(bookcontent.replace(' ', ''), "lxml")bookcontent = mysoup.find('div',{'id':'content'}).text.replace('一秒記住【筆趣閣 www.bbiquge.com】,精彩小說無彈窗免費閱讀!','').replace(u'\xa0', u' ')fr = open(filename , "a+")fr.write('\r\n' + titlename + '\r\n'+ bookcontent)#書名:透視醫圣
filename = '/home/topgrec/books/透視醫圣.txt'
if not os.path.exists(filename):os.system(r"touch {}".format(filename))#調用系統命令行來創建文件
fp = open(filename, 'r', encoding='utf-8')
allcontent = fp.read()#取得所有章節列表(書名--透視醫圣)
rooturl = "https://www.bbiquge.com/book_46894/"
response = requests.get(rooturl)
rootcontent = response.content.decode('gbk')
soup = BeautifulSoup(rootcontent,"lxml")
booklist = soup.select('dd a')#取得各個章節的內容(書名--透視醫圣)
for info in booklist:s = info.textpat = re.search(s, allcontent) #判斷該章節是否已經存在,不存在才下載if not pat:getdetails(info) #書名:豪婿
filename = '/home/topgrec/books/豪婿.txt'
if not os.path.exists(filename):os.system(r"touch {}".format(filename))#調用系統命令行來創建文件
fp = open(filename, 'r', encoding='utf-8')
allcontent = fp.read()#取得所有章節列表(書名--豪婿)
rooturl = "https://www.bbiquge.com/book_124646/"
response = requests.get(rooturl)
rootcontent = response.content.decode('gbk')
soup = BeautifulSoup(rootcontent,"lxml")
booklist = soup.select('dd a')#取得各個章節的內容(書名--豪婿)
for info in booklist:s = info.textpat = re.search(s, allcontent) #判斷該章節是否已經存在,不存在才下載if not pat:getdetails(info)
utf-8 轉 gbk
#!/bin/bash
directory="/home/topgrec/books"
f_encoding="utf-8"
t_encoding="gbk"
for file in `find $directory/*.txt -type f`
doif [ -f "$file" ]thenfname=`echo "$file" | awk -F '/' '{print $5}'`iconv -f $f_encoding -t $t_encoding $file -o $directory/iconv_$fnamemv $directory/iconv_$fname $filefi
done
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态