zoukankan      html  css  js  c++  java
  • 爬虫练习之正则表达式爬取猫眼电影Top100

    #猫眼电影Top100
    import requests,re,time

    def get_one_page(url):
    headers={
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
    }
    response=requests.get(url,headers=headers)
    if response.status_code == 200:
    return response.text
    return None

    def parse_one_page(html):
    pattern=re.compile('<dd>.*?board-index.*?>(.*?)</i>.*?title="(.*?)".*?<img data-src="(.*?)".*?<p class="star">(.*?)</p>.*?releasetime">(.*?)</p>.*?integer">(.*?)</i>.*?fraction">(.*?)</i>.*?</dd>',re.S)
    items=re.findall(pattern,html)
    for i in items:
    index,name,url,star,time,score1,score2=i
    url=url.strip()
    star=star.strip()
    time=time.strip()
    score=score1.strip()+score2.strip()
    print(index,name,url,star,time,score)

    def main(offset):
    url='https://maoyan.com/board/4?offset='+str(offset)
    html=get_one_page(url)
    #print(html)
    parse_one_page(html)

    if __name__=='__main__':
    for i in range(10):
    main(i*10)
  • 相关阅读:
    网络运维架构
    Q in Q
    光纤/光模块的多模和单模
    Cisco VTP
    Cisco NTP配置
    惠普/aruba交换机
    【转】交换机背板带宽
    接入交换机下所有服务器不定时丢包
    windows 2012安装不了KB2919355
    Cisco交换机密码策略设置
  • 原文地址:https://www.cnblogs.com/wsw-seu/p/10516905.html
Copyright © 2011-2022 走看看