请问搜索后运行结果是1怎么回事啊?
import requests
import parsel
def get_response(html):
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
}
response = requests.get(html, headers=headers)
return response
# 提取小说名称和所有章节的链接列表
def get_novel_info(html):
html_data = get_response(html).text
selector = parsel.Selector(html_data)
name = selector.css(".info h1::text").get()
href = selector.css(".listmain dd a::attr(href)").getall()
link_list = ['https://www.bqgbe.com/' + i for i in href]
return name, link_list
def get_content(html):
link_data = get_response(html=html).text
link_selector = parsel.Selector(link_data)
print(link_selector)
title = link_selector.css('.content h1::text').get()
content = '\n'.join(link_selector.css('#chaptercontent::text').getall())
return title, content
def save(name, title, content):
with open(name + '.txt', mode='a', encoding='utf-8') as f:
f.write(str(title))
f.write('\n')
f.write(str(content))
f.write('\n')
print('保存: ', title)
def search(word):
search_url=f'https://www.bqgka.com/user/search.html?q={word}'
json_data=get_response(html=search_url).json()
print(json_data)
if __name__ == "__main__":
search('弃宇宙')
# url="https://www.bqgka.com/book/3315/"
# name, link_list = get_novel_info(html=url)
#
# for link in link_list:
# title, content = get_content(html=link)
#
# save(name=name, title=title, content=content)
# print(link)