Python实战1_1:做一个自己的网页

参加了Python实战课程,此为第一节课的练习总结

成果

这里写图片描述

HTML代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>The Blah</title>
    <link rel="stylesheet" type="text/css" href="homework.css">
</head>
<body>
    <div class="header">
        <img src="images/blah.png">
        <ul class="nav">
            <li><a href="#">Home</a></li>
            <li><a href="#">Site</a></li>
            <li><a href="#">Other </a></li>
        </ul>
    </div>
    <div class="main-content">
        <h2>The Beach</h2>
        <hr />
        <ul class="photos">
            <li><img  src="images/0001.jpg" width="150" height="150"></li>
            <li><img  src="images/0003.jpg" width="150" height="150"></li>
            <li><img  src="images/0004.jpg" width="150" height="150"></li>
        </ul>
        <p>stretching from Solta to Mljet, and this unique cycling trip captures the highlights with an ideal balance of activity, culture and relaxation. Experience the beautiful island of Korcula with its picturesque old town, the untouched beauty of Vis, and trendy Hvar with its Venetian architecture. In the company of a cycling guide, this stimulating journey explores towns and landscapes, many of which are on UNESCO's world heritage list. Aboard the comfortably appointed wooden motor yacht, there is ample time between cycles to swim in the azure waters and soak up the ambience of seaside towns. </p>

    </div>
    <div class="footer">
        <p>&copy;MUGGLECODING</p>
    </div>
</body>
</html>

总结

  • 了解了网页结构组成。
  • js是用于控制html页面代码,实现复杂的页面效果或功能
  • css用于功能html如何展示,让页面展示的美观漂亮
  • html用于描述网页结构。
  • 学会了如何使用css结构去控制页面样式(css是老师写好的)
  • 14
    点赞
  • 87
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,您想了解关于Python爬取豆瓣小组动态网页话题数据的相关内容,是吗?那我来简单介绍一下。 豆瓣小组的话题数据是通过Ajax动态加载的,因此我们需要模拟浏览器发送Ajax请求,获取动态数据。具体的实现过程可以分为以下几个步骤: 1. 解析动态网页的URL,获取Ajax请求的参数。 豆瓣小组话题数据的动态网页URL为:https://www.douban.com/group/topic/XXX/?start=YYY 其中,XXX为话题的ID,YYY为话题的起始位置。我们需要根据话题ID和起始位置构造Ajax请求的参数。 ```python import re import requests url = 'https://www.douban.com/group/topic/{}/?start={}' topic_id = '123456' # 话题ID start = 0 # 起始位置 ajax_url = url.format(topic_id, start) # 解析话题ID和起始位置 html = requests.get(url).text topic_id = re.search(r'topic/(\d+)/', html).group(1) start = 0 ajax_url = url.format(topic_id, start) ``` 2. 发送Ajax请求,获取动态数据。 ```python import json headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3', 'X-Requested-With': 'XMLHttpRequest' } response = requests.get(ajax_url, headers=headers) data = json.loads(response.text) ``` 其中,headers中添加了X-Requested-With字段,用于模拟Ajax请求。response是服务器响应的HTTP响应对象,data是响应内容的JSON格式。 3. 解析动态数据,提取话题内容。 ```python from bs4 import BeautifulSoup soup = BeautifulSoup(data['html'], 'html.parser') for topic in soup.find_all('tr', class_=''): # 遍历所有话题 title = topic.find('a', class_='title')['title'] # 话题标题 content = topic.find('p', class_='').get_text().strip() # 话题内容 author = topic.find('a', class_='').get_text().strip() # 话题作者 reply_time = topic.find('td', class_='time').get_text().strip() # 回复时间 reply_count = topic.find('td', class_='').get_text().strip() # 回复数 view_count = topic.find('td', class_='').get_text().strip() # 浏览数 ``` 其中,使用BeautifulSoup解析动态数据的HTML代码,通过find_all方法获取所有话题的tr元素,然后提取话题的标题、内容、作者、回复时间、回复数和浏览数等信息。 以上就是Python爬取豆瓣小组动态网页话题数据的基本步骤,具体的实现细节还需要根据具体的需求进行调整。希望能对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值