gpt4 book ai didi

python - 属性错误 : 'NoneType' object has no attribute 'find'

转载 作者:行者123 更新时间:2023-12-04 00:05:42 25 4
gpt4 key购买 nike

我必须通过网站上的搜索查询来搜索 CVE 或常见漏洞和暴露,然后在我的打印请求中打印导入结果表。我用来抓取结果的网站是 https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=CVE+2017

我正在使用 python 3 进行编码,并且是新手,想将其用作项目

import urllib.request
import urllib
searchStr = input("Enter Search Query \n")
r = urllib.request.urlopen("https://cve.mitre.org/cgi-bin/cvekey.cgi?
keyword="+searchStr)
source_code = r.read()
from bs4 import BeautifulSoup
soup = BeautifulSoup(source_code, 'html.parser')
table = soup.find('tbody', id = 'TableWithRules')
rows = table.find('tr')
for tr in rows:
cols = tr.find('td')
p = cols[0].text.strip()
d = cols[1].text.strip
print(p)
print(d)

给我以下错误:

Traceback (most recent call last):
File "C:\Users\Devanshu Misra\Desktop\Python\CVE_Search.py", line 9, in
<module>
rows = table.find('tr')
AttributeError: 'NoneType' object has no attribute 'find'

最佳答案

“正确”的答案不正确
这一行是错误的:

divtag=soup.find('div',{'id':'TableWithRules'})

应该是:

table=soup.find('div',{'id':'TableWithRules'})

关于python - 属性错误 : 'NoneType' object has no attribute 'find' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46582882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com