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()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM