一个爬虫小实例
import requests

def get_html(url):
    r = requests.get(url)
    html = r.content.decode()
    return html
def parse_data(data):
    lines = []
    url = ''
    for line in data.split('\n'):
        if '下一章' in line:
            url = line.split('"')[1] .strip() 
            break
        if line.startswith('<p>') and '=' not in line:
            line = line.strip()[3:-4]
            lines.append(line + '\n')
    return lines, url
def write_file(content):
    with open('平凡的世界.txt', 'a')  as f:
        f.writelines(content)
def main(url):
    while url:
        html = get_html(url)
        content, url = parse_data(html)
        write_file(content)
        if '06.html' in url:
            break
    
if __name__ == '__main__':
    data_url = 'http://www.pingfandeshijie.net/di-yi-bu-01.html'
    main(data_url)


暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇