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

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

資源簡介

實現python爬取小說

資源截圖

代碼片段和文件信息

#?-*-?coding:utf-8?-*-
import?re
import?requests
url?=?“http://mianzhuan.wddsnxn.org“
headers?=?{‘User-Agent‘:?‘Mozilla/5.0?(Windows?NT?6.1;?WOW64)?AppleWebKit/535.1?\
????(KABUL?like?Gecko)?Chrome/14.0.835.163?Safari/535.1‘}
params?=?{‘tickers‘:?‘MST‘?‘date‘:?‘2020-07-15‘}
response?=?requests.get(urlheaders=headersparams=params)

response.encoding=‘utf-8‘
html?=?response.text
#print(html)
#獲取小說的標題

title?=?re.findall(r‘?(.*?)?‘html)
#print(title)

url?=?re.findall(r‘?.*??‘html)
#print(url)

#新建文件
fb?=?open(“note.txt“‘w‘encoding=‘utf-8-sig‘)

#for循環迭代?下載每一個章節

i?=?0
for?info?in?url:
????info_response?=?requests.get(infoheaders=headersparams=params)
????info_response.encoding?=?‘utf-8-sig‘
????info_html?=?info_response.text
#info_html
????#提取章節內容
????content?=?re.findall(r‘(.*?)ript?language=“javascript“.*?>‘info_html)
????#print(content)

????#清洗數據
????content=content[0].replace(“
““\n“)
????content?=?content.replace(““““)
????#

評論

共有 條評論