我正在尝试获取与用户试图访问的任何网站相关的信息。为了阻止任何恶意网站访问,我需要像黑名单状态,IP地址,服务器位置等详细信息。我从URLVOID网站得到这个。<;https://www.urlvoid.com/scan/>
我得到了以下表格格式的结果,并试图在spyder中获取相同的结果。 See the Table
我使用regex方法从表中获取详细信息。在
######
import httplib2
import re
def urlvoid(urlInput):
h2 = httplib2.Http(".cache")
resp, content2 = h2.request(("https://www.urlvoid.com/scan/" + urlInput), "GET")
content2String = (str(content2))
rpderr = re.compile('\<div\sclass\=\"error\"\>', re.IGNORECASE)
rpdFinderr = re.findall(rpderr,content2String)
if "error" in str(rpdFinderr):
ipvoidErr = True
else:
ipvoidErr = False
if ipvoidErr == False:
rpd2 = re.compile('(?<=Server Location</span></td><td>)[a-zA-Z0-9.]+(?=</td></tr>)')
rpdFind2 = re.findall(rpd2,content2String)
rpdSorted2=sorted(rpdFind2)
return rpdSorted2
urlvoid("google.com")
######
然而,它的效率不高,而且这个正则表达式并不适用于所有的网站。有没有更简单的方法来获取所有这些信息?在
我不建议您使用regex来获取数据,因为它可以通过
bs4
来完成,并且如果您构建一个regex来完成,则需要较长的时间和复杂的条件。在相关问题 更多 >
编程相关推荐