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

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

網絡爬蟲爬取小說3

2019-11-11 02:55:03
字體:
來源:轉載
供稿:網友
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的使用,歡迎指教(野路子)
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 观塘区| 新兴县| 腾冲县| 文成县| 会东县| 潮州市| 镶黄旗| 五华县| 固阳县| 信阳市| 文山县| 芦溪县| 平阴县| 晋江市| 红桥区| 曲水县| 永福县| 永和县| 尼勒克县| 长春市| 刚察县| 清水河县| 涞水县| 横峰县| 安仁县| 旬阳县| 农安县| 孝义市| 高陵县| 阿拉善盟| 东阳市| 台南市| 武汉市| 临安市| 福泉市| 漳浦县| 土默特左旗| 栾城县| 永善县| 米泉市| 高阳县|