zoukankan      html  css  js  c++  java
  • 《Forward团队-爬虫豆瓣top250项目-开发文档》

    码云地址:https://github.com/xyhcq/top250 

    模块功能:获取豆瓣top250网页的源代码,并分析。

    def getHTMLText(url,k):
        # 获取网页源代码
        try:
            if(k==0):
                kw={}
            else:
                kw={'start':k,'filter':''}
            # 保存获取的网页
            read = requests.get(url,params=kw,headers={'User-Agent': 'Mozilla/4.0'})
            read.raise_for_status()
            read.encoding = read.apparent_encoding
            return read.text
        except:
            print("获取失败!")
    
    def getData(html):
        # 分析代码信息,提取数据
        soup = BeautifulSoup(html, "html.parser")
    
        # 找到第一个class属性值为grid_view的ol标签
        movieList=soup.find('ol',attrs={'class':'grid_view'})
    
    
        # 找到所有的li标签
        for movieLi in movieList.find_all('li'):    
            # 找到第一个class属性值为hd的div标签
            movieHd=movieLi.find('div',attrs={'class':'hd'})
  • 相关阅读:
    css清除浮动
    对象遍历
    vue 小工具
    数据库优化-聚合索引
    mysql修改唯一索引
    输出带pre的调试信息
    mysql的group by优化跟limit优化
    地址联动数据抓取
    php7新特新
    linux同步系统时间
  • 原文地址:https://www.cnblogs.com/mazhuangmz/p/7780196.html
Copyright © 2011-2022 走看看