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

import requests
import re

domain = "https://www.dytt89.com/"
#resp = requests.get(domain, verify=False)#如果需要SSl,加verify,表示去掉安全验证

resp = requests.get(domain)
resp.encoding = "gb2312"
#print(resp.text) #乱码,会看到网页编码是gb2312,需要做解码为gb2312
"""
#内容:
            <div class="co_area2" style="float:left;width:470px;height:auto;overflow:hidden;margin-left:6px;">
                <div class="title_all"><p><span style="float:left;">2022必看热片</span><em style="float:right;"><a href="/html/bikan/">更多>></a></em></p></div>
                <div class="co_content222">
                    <ul>
                        <li><a href='/i/105424.html' title="2022年美国7.6分动作犯罪片《新蝙蝠侠》HD中英双字">2022年美国7.6分动作犯罪片《新蝙蝠侠》HD中英双字</a><span><font color=#FF0000>04-19</font></span></li>
<li><a href='/i/105405.html' title="2022年国产7.4分剧情片《奇迹·笨小孩》HD国语中字">2022年国产7.4分剧情片《奇迹·笨小孩》HD国语中字</a><span><font color=#FF0000>04-15</font></span></li>
<li><a href='/i/105296.html' title="2022年国产6.5分喜剧片《这个杀手不太冷静》HD国语中字">2022年国产6.5分喜剧片《这个杀手不太冷静》HD国语中字</a><span><font color=#FF0000>04-02</font></span></li>
<li><a href='/i/105283.html' title="2022年美国科幻灾难片《月球陨落》BD中英双字">2022年美国科幻灾难片《月球陨落》BD中英双字</a><span><font color=#FF0000>03-31</font></span></li>
<li><a href='/i/105259.html' title="2022年国产7.7分战争历史片《狙击手》HD国语中字">2022年国产7.7分战争历史片《狙击手》HD国语中字</a><span><font color=#FF0000>03-26</font></span></li>
<li><a href='/i/101839.html' title="2020年美国8.2分动作犯罪片《绅士们》蓝光中英双字">2020年美国8.2分动作犯罪片《绅士们》蓝光中英双字</a><span><font color=#FF0000>03-22</font></span></li>
<li><a href='/i/105188.html' title="2022年美国8.3分动画片《青春变形记》BD国粤英三语中字">2022年美国8.3分动画片《青春变形记》BD国粤英三语中字</a><span><font color=#FF0000>03-20</font></span></li>
<li><a href='/i/104733.html' title="2021年美国动作科幻片《黑客帝国:矩阵重启》蓝光国英双语中英双字">2021年美国动作科幻片《黑客帝国:矩阵重启》蓝光国英双语中英双</a><span><font color=#FF0000>03-19</font></span></li>
<li><a href='/i/105212.html' title="2022年国产动画片《小虎墩大英雄》HD国语中字">2022年国产动画片《小虎墩大英雄》HD国语中字</a><span><font color=#FF0000>03-18</font></span></li>
<li><a href='/i/105182.html' title="2021年美国7.5分动作科幻片《蜘蛛侠:英雄无归》蓝光中英双字">2021年美国7.5分动作科幻片《蜘蛛侠:英雄无归》蓝光中英双字</a><span><font color=#FF0000>03-15</font></span></li>
<li><a href='/i/105114.html' title="2021年中国香港动作犯罪片《反贪风暴5:最终章》HD双语中字">2021年中国香港动作犯罪片《反贪风暴5:最终章》HD双语中字</a><span><font color=#FF0000>02-27</font></span></li>
<li><a href='/i/105028.html' title="2021年美国喜剧动作片《王牌特工:源起》蓝光特效中英双字">2021年美国喜剧动作片《王牌特工:源起》蓝光特效中英双字</a><span><font color=#FF0000>02-21</font></span></li>
<li><a href='/i/105057.html' title="2021年国产6.0分剧情片《穿过寒冬拥抱你》HD国语中字">2021年国产6.0分剧情片《穿过寒冬拥抱你》HD国语中字</a><span><font color=#FF0000>02-15</font></span></li>
<li><a href='/i/105005.html' title="2021年国产8.3分动画片《雄狮少年》HD国粤双语中字">2021年国产8.3分动画片《雄狮少年》HD国粤双语中字</a><span><font color=#FF0000>02-04</font></span></li>
<li><a href='/i/104994.html' title="2021年国产剧情犯罪片《误杀2》4K国语中字">2021年国产剧情犯罪片《误杀2》4K国语中字</a><span><font color=#FF0000>02-03</font></span></li>
                    </ul>
                </div>
            </div>
"""
# 拿到ul里面的li
obj1 = re.compile(r"2022必看热片.*?<ul>(?P<ul>.*?)</ul>", re.S)
# 从2022比看中提取子页面链接,也就是目前获得信息的href后面的信息
obj2 = re.compile(r"<a href='(?P<href>.*?)'", re.S)
# 获取片名
obj3 = re.compile(r'◎片  名(?P<movie>.*?)<br />.*?'
                  r'<td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><a href="(?P<download>.*?)">', re.S)

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:
        #href = itt.group("href")
        # 拼接子页面的url地址: 域名 + 子页面地址
        # print(href)  #拿到一堆链接,如:/i/105505.html
        child_href = domain + itt.group("href").strip("/")
        #print(child_href) # https://www.dytt89.com/i/105057.html
        child_href_list.append(child_href) #把子页面链接保存到列表

# 提取子页面内容
for href in child_href_list:
    child_resp = requests.get(href)
    child_resp.encoding = 'gb2312'
    #print(child_resp.text)
    result3 = obj3.search(child_resp.text)
    print(result3.group("movie"))
    print(result3.group("download"))
    #break  # 测试用,此时只会拿到一条数据就退出循环

电影天堂镜像 电影天堂镜像在线播放_html