Day32

Posted a352735549

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Day32相关的知识,希望对你有一定的参考价值。

1、爬虫

技术分享图片
import re
from urllib.request import urlopen

def getPage(url):
    response = urlopen(url)
    return response.read().decode(utf-8)

def parsePage(s):
    com = re.compile(
        <div class="item">.*?<div class="pic">.*?<em .*?>(?P<id>\d+).*?<span class="title">(?P<title>.*?)</span>
        .*?<span class="rating_num" .*?>(?P<rating_num>.*?)</span>.*?<span>(?P<comment_num>.*?)评价</span>, re.S)

    ret = com.finditer(s)
    for i in ret:
        yield {
            "id": i.group("id"),
            "title": i.group("title"),
            "rating_num": i.group("rating_num"),
            "comment_num": i.group("comment_num"),
        }

def main(num):
    url = https://movie.douban.com/top250?start=%s&filter= % num
    response_html = getPage(url)
    ret = parsePage(response_html)
    print(ret)
    f = open("move_info7", "a", encoding="utf8")
    for obj in ret:
        print(obj)
        data = str(obj)
        f.write(data + "\n")
    f.close()

if __name__ == __main__:
    count = 0
    for i in range(10):
        main(count)
        count += 25
View Code

 

以上是关于Day32的主要内容,如果未能解决你的问题,请参考以下文章

win32day04-Win32消息机制

win32day02-字符与编码

[code] PTA 胡凡算法笔记 DAY039

web代码片段

此 Canon SDK C++ 代码片段的等效 C# 代码是啥?

2021-09-11:给你一个32位的有符号整数x,返回将x中的数字部分反转后的结果。反转后整数超过 32 位的有符号整数的范围就返回0,假设环境不允许存储 64 位整数(有符号或无符号)。(代码片段