update
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
import requests
|
||||||
|
import bs4
|
||||||
|
import time
|
||||||
|
|
||||||
|
next_url = 'https://www.biqige.info/40_40641/9799877.html'
|
||||||
|
total_content = ''
|
||||||
|
while True:
|
||||||
|
url = next_url
|
||||||
|
response = requests.get(url)
|
||||||
|
soup = bs4.BeautifulSoup(response.content, features='lxml')
|
||||||
|
content = soup.select('#content')
|
||||||
|
try:
|
||||||
|
next_url = 'https://www.biqige.info' + soup.select_one('#wrapper > div.content_read > div > div.bottem2 > a:nth-child(4)')['href']
|
||||||
|
except Exception:
|
||||||
|
break
|
||||||
|
title = soup.select_one('h1').text
|
||||||
|
if content:
|
||||||
|
content = content[0].text.replace('\xa0', '')
|
||||||
|
else:
|
||||||
|
print(title, 'content error')
|
||||||
|
continue
|
||||||
|
total_content += title + '\n' + content + '\n'
|
||||||
|
print(title, 'completed')
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
with open('抗战之红色警戒.txt', 'w', encoding='utf-8') as file:
|
||||||
|
file.write(total_content.replace('\n\r\n', '\n\n'))
|
||||||
|
print('done')
|
||||||
Reference in New Issue
Block a user