爬虫 电影天堂

172 阅读1分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第10天

这里是课程的链接 2 4 屠戮盗版天堂电影信息(3)_哔哩哔哩_bilibili 我觉得老师讲的挺好,大家可以听听看,试一试爬虫,没准听着听着就会了呢哈哈 我现在的阶段是代码都可以运行出来,然后提取网页地址和print是差不多知道,出问题在网上搜就可以解决,感觉没干啥,但就是觉得打代码比之前顺手了一点。

然后把代码发给大家

# -*- coding:utf-8 -*-

1.定位到2022必看片 2.从2022必看片中提取到子页面的链接地址 3.请求子页面的链接,拿到我们想要的下载地址

import requests
import re

import urllib3

urllib3.disable_warnings()
domain = "https://www.dytt89.com/"

resp = requests.get(domain, verify=False)  

verify=False 去掉安全验证

resp.encoding = 'gb18030'  

指定字符集

print(resp.text)

拿到ul里面的li

obj1 = re.compile(r"2022必看热片.*?<ul>(?P<ul>.*?)</ul>", re.S)
obj2 = re.compile(r"<a href='(?P<href>.*?)'", re.S)
obj3 = re.compile(r'◎片  名(?P<movie>.*?)<br />.*?<td '
                  r'style="WORD-WRAP: break-word" bgcolor="#fdfddf"><a href="(?P<download>.*?)">')

result1 = obj1.finditer(resp.text)
child_href_list = []
for it in result1:
    ul = it.group('ul')

print(ul)

提取子页面链接:

 result2 = obj2.finditer(ul)
 for itt in result2:
 ```
 *拼接子页面的url地址: 域名+子页面地址*
 ```js
     child_href = domain + itt.group('href').strip("/")
     # print(itt.group('href'))
     child_href_list.append(child_href)  

把子页面链接保存起来

提取子页面内容


  for href in child_href_list:
      child_resp = requests.get(href, verify=False)
      child_resp.encoding = 'gb18030'
      print(child_resp.text)
      result3 = obj3.search(child_resp.text)

      print(result3.group("movie"))
      print(result3.group("download"))

break 测试用

image.png 然后我是运行出来了,但是下载链接有点问题不太会弄。反正是出来了

image.png