小說旗 單篇文章採集

2021-08-21 08:57:46 字數 3799 閱讀 4729

1、**文件格式:(**採集位址

2、免費**穩定性不可靠,採用裝飾器重連同時切換**

# coding: utf-8

# pyhotn 2.7

# **棋 單篇**採集

# 替換第一章位址,總章節數。

# ip.txt 為**池。

import urllib2

from bs4 import beautifulsoup

import sys

import traceback

import random

import gzip

reload(sys)

sys.setdefaultencoding('utf-8')

f = open("out.txt", "a+")

headers =

url = "book/18_18966/7828246.html"

# 第一章**

page = 184

# 章節數

nexthref = url

ippool =

defippool

(): reader = open('ip.txt')

line = reader.readline()

while line:

if line.strip() != '':

line = reader.readline()

reader.close()

retries = 0

# 重試的次數

count =

defconn_try_again

(function):

def(*args, **kwargs):

try:

return function(*args, **kwargs)

except exception, err:

print("--重試訪問,當前次數 %s ,(總次數11)--" % (count['num'] + 1))

if count['num'] < 10:

count['num'] += 1

else:

raise exception(err)

bsobj = none

#判斷編碼格式

defgetcoding

(strinput):

''' 獲取編碼格式

'''if isinstance(strinput, unicode):

return

"unicode"

try:

strinput.decode("utf8")

return

'utf8'

except:

pass

try:

strinput.decode("gbk")

return

'gbk'

except:

pass

@conn_try_again

defgetcontent

(url):

global nexthref, page, bsobj

# 定義乙個**開關

proxyswitch = true

try:

poollen = len(ippool)

if (poollen > 0):

i = random.randint(0, poollen - 1)

print(ippool[i])

proxy_host = ippool[i][2] + "://" + ippool[i][0] + ":" + ippool[i][1]

proxy_temp =

proxy_support = urllib2.proxyhandler(proxy_temp)

else:

print('--**池當前無可用**,使用本機位址訪問--')

proxy_support = urllib2.proxyhandler({})

nullproxy_handler = urllib2.proxyhandler()

if proxyswitch:

opener = urllib2.build_opener(proxy_support)

else:

opener = urllib2.build_opener(nullproxy_handler)

urllib2.install_opener(opener)

req = urllib2.request(url, headers=headers)

response = urllib2.urlopen(req, timeout=3)

r = response.read()

encode=getcoding(r)

if(encode==none):

print(response.info().get('content-encoding'))

#gzip需要解壓

else :

r = r.decode(encode)

# print(r)

bsobj = beautifulsoup(r, 'lxml')

except exception, err:

raise exception(err)

# print(bsobj)

contentdiv = bsobj.find('div', id='content')

content = bsobj.find('div', id='content').get_text()

preandnextbar = bsobj.find('div', id='thumb')

title = bsobj.find('div', id='bgdiv').h1.get_text()

if ("下一章"

in preandnextbar.get_text()):

next = none

alist = preandnextbar.findall('a')

for i in alist:

if ("下一章"

in i.get_text()):

next = i

if (next == none):

print("下一章為空")

return

true

nexthref = next.get('href')

print(title)

# print(content)

print(nexthref)

f.write("#####" + '\n')

f.write(title + '\n')

f.write(content + '\n')

count['num'] = 0

else:

return

true

defmain

(): ippool()

global page

try:

for num in range(1, page):

if (getcontent(nexthref)):

break

print("--- end ---")

except exception, e:

print(traceback.print_exc())

finally:

f.close()

main()

附:**採集

筆趣閣 單篇小說採集

1 文件格式 採集位址 2 免費 穩定性不可靠,採用裝飾器重連同時切換 coding utf 8 筆趣閣 單篇 採集 替換第一章位址,總章節數。ip.txt 為 池。import urllib2 from bs4 import beautifulsoup import sys import trac...

高仿書旗小說 Flutter 版,學起來

今天推薦乙個完整的開源專案,高仿書旗 flutter 版,學起來,躁起來。這是乙個用 flutter 寫的書旗 客戶端,主要實現的功能有 書城 3d 輪播 選單 五種通過 api 配置的卡片樣式 詳情 導航欄樣式切換動效 高斯模糊效果 文字伸縮 書架 頂部雲彩動效 導航欄樣式切換動效 書籍展示 我的...

python3安卓 在書旗小說發文怎麼樣

在書旗 發文怎麼樣被擠通導致得水1館洩不,特別的年高音星給輕明站台會唱一位。騰b圍繞第三代奔的五新優全新勢,脫口秀表趣橫展示了一演場妙生的。窪路底盤對坑系統面過濾感良好,班城必備日常通工的交勤和旅遊絕對家庭具出行是是上下市通,感輕盤手盈方向。讓整罩金鐘車變成了防撞,同時動安全上在被,內乘為車供了效的...