天天看點

python爬蟲超簡單執行個體

import requests #導入必備神器requests
import re #導入正則

url='http://www.jjwxc.net/onebook.php?novelid=109034&chapterid=1' 
response=requests.get(url)
response.encoding='gb2312'#根據要爬的網頁的編碼進行編碼
html=response.text #轉換成文本

info=re.findall(r'<div style="clear:both;"></div>([\s\S]*)<div id="favoriteshow_3" style="display:none" align="center"></div>',html)[0]
#使用正則進行比對小說内容      
print(info)#列印