zoukankan      html  css  js  c++  java
  • 骑行入门

    对每一个骑者的入门进行推荐,爬虫:

    import re
    import requests
    from bs4 import BeautifulSoup
    import csv
    
    def paqu():
        f = open('../../Documents/Tencent Files/631836111/FileRecv/骑行入门.csv', 'a+', encoding='utf-8', newline='')
        csv_writer = csv.writer(f)
        csv_writer.writerow(["题目", "内容链接", "详细内容"])
        headers = {
                'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36',
            }
        link = 'http://www.biketo.com/beginnerguide/'
        r = requests.get(link, headers=headers, timeout=10)
        soup = BeautifulSoup(r.text, "lxml")
        li_list = soup.find_all('li')[4:140]
        for each in li_list:
            txt=each.find('a').string
            href=each.find('a')['href']
            print(txt + "      " + href)
            Response = requests.get(href, headers=headers, timeout=10)
            soup1 = BeautifulSoup(Response.text, "lxml")
            div_list = soup1.find_all('p', style='text-indent:2em;')
            #div_list= soup1.find_all('div',class_='article-content')
    
            txt1=[]
            for each1 in div_list:
                if(each1.string is not None):
                    txt1.append(each1.string)
            #print(*txt1)
            csv_writer.writerow([txt, href,*txt1])
    
    if __name__ == '__main__':
        paqu()

    获得的数据:

    是多疑还是去相信 谎言背后的忠心 或许是自己太执迷 命题游戏 沿着他的脚步 呼吸开始变得急促 就算看清了面目 设下埋伏 真相却居无定处 I swear I'll never be with the devil 用尽一生孤独 没有退路的路 你看不到我 眉眼焦灼却不明下落 命运的轮轴 伺机而动 来不及闪躲 沿着他的脚步 呼吸开始变得急促 就算看清了面目 设下埋伏 真相却居无定处 I swear I'll never be with the devil 用尽一生孤独 没有退路的路 你看不到我 眉眼焦灼却不明下落 命运的轮轴 伺机而动 来不及闪躲 你看不到我 眉眼焦灼却不明下落 命运的轮轴 伺机而动 来不及闪躲 黑夜和白昼 你争我夺 真相被蛊惑 心从不退缩 这天堂荒漠 留给孤独的猎手
  • 相关阅读:
    VScode出现无法打开“X”: 找不到文件(file:///XXXX) 的解决办法
    Re:0通过服务器自建内网穿透远程桌面(10分钟可完成)
    (补题 POJ 3013) Big Christmas Tree
    (补题 cf 1140)Detective Book
    (2019.9.5~2019.9.11)补题汇总(字符串相关)
    最小生成树(克鲁斯卡尔算法)
    最短路问题
    字符串匹配(部分整理)
    Linux内核分析——第八周学习笔记
    《Linux内核设计与实现》第四章读书笔记
  • 原文地址:https://www.cnblogs.com/muailiulan/p/14534388.html
Copyright © 2011-2022 走看看