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

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

網(wǎng)絡(luò)爬蟲(chóng)爬取小說(shuō)3

2019-11-11 01:44:36
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
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,"大主宰") 
這個(gè)是對(duì)于第三方庫(kù)BeautifulSoup的使用,歡迎指教(野路子)
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 正阳县| 甘洛县| 洛扎县| 南雄市| 南和县| 江城| 桦甸市| 崇礼县| 绵竹市| 黔江区| 张北县| 子洲县| 徐汇区| 淮南市| 汝南县| 库伦旗| 聂拉木县| 平阴县| 敖汉旗| 乐安县| 云南省| 涞水县| 巴彦淖尔市| 花垣县| 米泉市| 孝义市| 海门市| 翁源县| 英德市| 武汉市| 汝南县| 鄂伦春自治旗| 罗源县| 仙居县| 临夏市| 洪泽县| 阿鲁科尔沁旗| 沧源| 伊宁市| 大关县| 炉霍县|