我有这个错误:
>C:\Python27\python.exe ShodanHostSeeker.py
Made by Zaseth.
Your target IP: 19290334
Traceback (most recent call last):
File "ShodanHostSeeker.py", line 12, in <module>
openPorts = soup.find("meta", attrs={"name": "twitter:description"})["content"]
TypeError: 'NoneType' object has no attribute '__getitem__'
我正在使用Python 2.7。 我的代码:
from bs4 import BeautifulSoup
import requests
s = requests.Session()
print("Made by Zaseth.")
shodanURL = input("Your target IP: ")
r = s.get('https://www.shodan.io/host/' + str(shodanURL))
soup = BeautifulSoup(r.text, "html.parser")
openPorts = soup.find("meta", attrs={"name": "twitter:description"})["content"]
print(openPorts)
tableElements = [element.contents[0] for element in soup.find("table", attrs={"class": "table"}).findAll("td")]
print(tableElements)
tableContents = [element.contents[0] for element in soup.find("table", attrs={"class": "table"}).findAll("th")]
print(tableContents)
有谁知道为什么会这样? 我真的迷路了,我已经用Google搜索过了。