python - 如何在 urlopen 响应中搜索特定字符串?
问题描述
我想查看 Troy Hunt 的网站“ https://haveibeenpwned.com/Passwords ”,如果他发布了新的密码文件,则使用 Python 进行自动化。为此,我阅读了该网站并想在其中搜索一个字符串以获取该文件的当前版本。这些总是以模式 ....v5.7z 命名。v 在这里代表版本。
# -*- coding: utf-8 -*-
import os
import urllib2
#from urllib2 import Request
from urllib2 import Request, urlopen, URLError, HTTPError
someurl='https://haveibeenpwned.com/Passwords'
req = Request(someurl, headers={'User-Agent': 'Mozilla/5.0'})
try:
response = urlopen(req)
except HTTPError as e:
print 'The server couldn\'t fulfill the request.'
print 'Error code: ', e.code
except URLError as e:
print 'We failed to reach a server.'
print 'Reason: ', e.reason
else:
print "everything is fine"
response = urllib2.urlopen(req)
the_page = response.read()
print(the_page)
在 "the_page" 中是页面的整个 HTML 代码。我该如何搜索它?
我不允许使用 beautifulsoap 或解析器..
解决方案
推荐阅读
- java - 自定义列表视图未完全显示(从底部裁剪)
- c - 在 C 中运行时评估 switch 表达式
- c++ - C++:重命名 dll 和库以及链接
- reactjs - 不同组件之间的 React 状态管理
- scope - 避免无意中使用照应宏的陷阱
- java - @ManyToOne 关系在 Spring Data REST 中插入空对象
- android - 无法解析此 JSON 数组。带有子数组和对象
- uwp - 为 MarkdownTextBlock 控件设置 LineHeight
- haskell - 如何在 Haskell 中转换代数数据类型?
- linq - 如何使用 Linq-to-SQL 在查询结果中创建汇总列?