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

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

網絡爬蟲爬取小說3

2019-11-11 01:02:30
字體:
來源:轉載
供稿:網友
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的使用,歡迎指教(野路子)
上一篇:mybatis 多對多

下一篇:100. Same Tree

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黄平县| 云浮市| 江油市| 开平市| 南溪县| 和林格尔县| 钦州市| 恭城| 永清县| 东辽县| 阜南县| 边坝县| 冷水江市| 福安市| 天津市| 贵南县| 汝阳县| 班戈县| 平泉县| 思茅市| 正蓝旗| 武汉市| 新闻| 桂阳县| 临夏市| 时尚| 永靖县| 株洲市| 潜江市| 鹤庆县| 霍林郭勒市| 临桂县| 册亨县| 揭东县| 攀枝花市| 文昌市| 德格县| 丰台区| 报价| 泾川县| 澄江县|