我一直在尝试使用条带()从HTML文件中获取文本,但这对我来说没有用,我不知道如何使用python从一个长的html页面中获取文本?
例:
import urllib.request
import sys
with urllib.request.urlopen('http://ctf.slothparadise.com/walled_garden.php?name=BMX') as response:
html= response.read()
html = str(html)
而我需要得到的上限,以完成挑战,并得到关键,请帮助:D谢谢
发布于 2018-02-17 22:19:12
您需要一个HTML,对于python,我强烈推荐美汤,
美丽的Soup是一个Python库,用于从HTML和XML文件中提取数据。它与您最喜欢的解析器一起工作,提供导航、搜索和修改解析树的惯用方法。它通常可以节省程序员的工作时间或天数。
安装:
pip install bs4
用法:
from bs4 import BeautifulSoup
html_string = "<html><head><title>This is a title</title></head><body></body></html>"
soup = BeautifulSoup(html_string, 'html.parser')
print soup.title # => "This is a title"
发布于 2018-02-17 22:23:16
如前所述,我建议使用BeautifulSoup。但是,如果您想要快速修复解决方案,那么只需使用regex来查找captcha。
import urllib.request
import sys
import re
with urllib.request.urlopen('http://ctf.slothparadise.com/walled_garden.php?
name=BMX') as response:
html= response.read()
html = str(html)
#get the captcha
print(re.findall(r'<pre>(.*?)</pre>', html))
https://stackoverflow.com/questions/48846379
复制相似问题