国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

網絡爬蟲爬取小說3

2019-11-11 01:44:26
字體:
來源:轉載
供稿:網友
from urllib import requestfrom bs4 import BeautifulSoupimport redef getHtml(url ):    page = request.urlopen(url)    html_doc = page.read()    html_doc = html_doc.replace(u'/xa0', u' ')    html_doc = str(html_doc)    html_doc = html_doc.replace("<br/>","/n")    return html_docdef getTitle(soup):    return soup.title.stringdef getContent(soup):    return soup.find(id="content").get_text()def getNextURL(soup):    next_init_url = str(soup.find(id="pager_next"))    next_url = re.search("/d+/.html", next_init_url)    if next_url is None:        return False    return next_url.group()def getBook(url,name):    txt = ''    book = open("./res/"+name,"w+")    while bool(url):        html_doc = getHtml(url)        soup = BeautifulSoup(html_doc, 'html.parser')        title = soup.title.string        book_content = soup.find(id="content").get_text()        book.write(title+book_content)        if bool(getNextURL(soup)):            url = re.sub("/d+.html", getNextURL(soup), url)        else:            break    if not book.closed:        book.close()    PRint("ok")url = "http://www.biqulou.net/24/24835/7406090.html"# url = "http://www.biqulou.net/24/24835/14627850.html"getBook(url,"大主宰") 
這個是對于第三方庫BeautifulSoup的使用,歡迎指教(野路子)
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大丰市| 嵊州市| 衡水市| 武清区| 汤阴县| 遂溪县| 商南县| 通州市| 寻乌县| 平舆县| 丹凤县| 大新县| 双流县| 黄石市| 武川县| 中江县| 思南县| 大名县| 五指山市| 田东县| 石屏县| 深泽县| 隆回县| 霍山县| 长顺县| 呈贡县| 吉隆县| 延长县| 阿尔山市| 临沂市| 青浦区| 柘荣县| 新乡县| 苗栗市| 汝南县| 文山县| 子洲县| 什邡市| 樟树市| 盈江县| 瑞金市|