zoukankan      html  css  js  c++  java
  • Python爬取腾讯视频电影名称和链接(一)

     1 import requests
     2 import json
     3 from bs4 import BeautifulSoup       #网页解析获取数据
     4 import sys
     5 import re
     6 import urllib.request,urllib.error #制定url,获取网页数据
     7 import sqlite3
     8 import xlwt     #excel操作
     9 
    10 def get_ten():
    11     url="https://v.qq.com/channel/movie?_all=1&channel=movie&listpage=1&sort=18"
    12     headers={
    13         'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '+
    14                        'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36'
    15     }
    16     # res = urllib.request.urlopen(url)
    17     res = urllib.request.Request(url=url,headers=headers)       #编辑request请求
    18     response=urllib.request.urlopen(res).read().decode()        #读取
    19     html=BeautifulSoup(response,"html.parser")      #解析
    20     #
    21     # list=html.select(".figure_score")
    22     # for item in list:
    23     #     print(item)
    24     dataRes=[]
    25     findLink=re.compile(r'href="(.*?)"')        #链接
    26     findName=re.compile(r'title="(.*?)"')       #影片名
    27     soup=html.find_all(r"a",class_="figure")
    28     for i in soup:
    29         # print(i)
    30         words=str(i)
    31         dataRes.append(re.findall(findLink,words))       #添加链接
    32         dataRes.append(re.findall(findName,words))       #添加影片名
    33     for i in dataRes:
    34         print(i)
    35     # print(html)
    36     # print(html.head.contents)       #输出tag的所有子节点(list)
    37     # print(response)
    38     return res
    39 if __name__ == '__main__':
    40     get_ten()

  • 相关阅读:
    div标签和span标签的简单区别
    方法重载的好处及区别
    异步计算工具
    设置"用于统计的冗余字段"要谨慎
    如何建立索引
    NFS,Memcached,Tokyo tyrant实现session共享性能测试
    mysql cache功能小记
    PHP程序员也要学会使用“异常”
    xdebug: var_dump函数设置
    用shell写个简单的log监控程序
  • 原文地址:https://www.cnblogs.com/rainbow-1/p/14708814.html
Copyright © 2011-2022 走看看