爬豆瓣网电影TOP250名单 ------- 代码未写完,等待更新

import requests
from requests.exceptions import RequestException
import re
import json def get_one_page(url):
try:
response = requests.get(url)
if response.status_code == 200:#判断网页是否正常开启
return response.text#返回没有
return None
except RequestException:
return None def parse_one_page(html):
pattern = re.compile("", re.S)#笔记本屏幕太小看不过来
items = re.findall(pattern, html) for item in items:#把爬取的信息进行格式化
yield{
"":item[0],
"":item[1],
} def write_to_file(content):
with open("result.txt", "a", encoding="utf-8") as f:
f.write(json.dumps(content, ensure_ascii=False) + "\n")
f.close() def main():
url = "https://movie.douban.com/top250"
html = get_one_page(url)
# parse_one_page(html)
for item in parse_one_page(html):
print(item)
write_to_file(item) if __name__ == "__main__":
main() #这段代码没有加RE的匹配方式(笔记本屏幕小)
#第二个这段代码只能匹配一页的东西,自己发挥想象把

最新文章

  1. (转)SVN服务器搭建和使用(一)
  2. High购电商系统开发注意点
  3. 在Fedora 20 上安装Mysql并初始化root密码
  4. iOS开发技巧
  5. 用Javascript取float型小数点
  6. tcpdump抓包
  7. Centos 安装 p7zip,即Linux下的7z
  8. [设计模式]Netd中的命令设计模式
  9. php使用mysql_query查询超大结果集超内存的解决方法
  10. 扩展ArcGIS API for Silverlight/WPF 中的TextSymbol支持角度标注
  11. Android开发之SoundPool使用具体解释
  12. Vue-cli 记录
  13. LeetCode 15. 3Sum(三数之和)
  14. Tomcat内核之ASCII解码的表驱动模式
  15. SQL优化 MySQL版 -分析explain SQL执行计划与Extra
  16. AOP - 2 实例(SpringBoot 注解方式)
  17. 算法实践--最长公共子序列(Longest Common Subsquence)
  18. free命令详解
  19. Python把两个列表合成一个字典
  20. Getting started with Processing 第十三章——延伸(1)

热门文章

  1. 【bzoj1028】[JSOI2007]麻将
  2. bzoj3332: 旧试题
  3. hdu 4123(树形dp+倍增)
  4. 安装nghttp2 报错error: Libtool library used but 'LIBTOOL' is undefined
  5. Timer A UP mode 中断
  6. 一款使用C# .NET开发的SIP网络电话客户端完整源码
  7. PCB Genesis脚本 C#调用Javascript
  8. 基于ASP.Net Core开发一套通用后台框架记录-(项目的搭建)
  9. Linux 本命令 基本上用到的命令-自己留着用
  10. 动态规划DP入门