作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从国家漏洞数据库 (http://web.nvd.nist.gov) 中抓取一些数据。我想要做的是输入一个搜索词,它会给我带来前 20 个结果,抓取这些数据。然后我想单击“下一个 20”,直到遍历所有结果。
我能够成功提交搜索词,但单击“下一个 20”根本不起作用。
我使用的工具是 Python + Mechanize
这是我的代码:
# Browser
b = mechanize.Browser()
# The URL to this service
URL = 'http://web.nvd.nist.gov/view/vuln/search'
Search = ['Linux', 'Mac OS X', 'Windows']
def searchDB():
SearchCounter=0
for i in Search:
# Load the page
read = b.open(URL)
# Select the form
b.select_form(nr=0)
# Fill out the search form
b['vulnSearchForm:text'] = Search[int(SearchCounter)]
b.submit('vulnSearchForm:j_id120')
result=b.response().read()
file=open(Search[SearchCounter]+".txt","w")
file.write(result)
'''Here is where the problem is. vulnResultsForm:j_id116 is value of the "next 20 button'''
b.select_form(nr = 0)
b.form.click('vulnResultsForm:j_id116')
result=b.response().read()
if __name__ == '__main__':
searchDB()
最佳答案
来自 b.form.click
的文档字符串:
Return request that would result from clicking on a control.
The request object is a urllib2.Request instance, which you can pass to urllib2.urlopen (or ClientCookie.urlopen).
request = b.form.click('vulnResultsForm:j_id116')
b.open(request)
result = b.response().read()
关于python - 从国家漏洞数据库中抓取数据 : can't figure out clicking on a button (Mechanize+Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4396774/
我是一名优秀的程序员,十分优秀!