【发布时间】:2017-09-14 03:57:49
【问题描述】:
我最近在使用 Python Mechanize 和 BeautifulSoup,我学会了如何点击和点击链接。
我现在想从 HTML 输入中获取一个值,我非常接近它,但我的代码是 可怕的!
我想print 只是
9574363984643591128220162336881714997023153074560071601385105141859609
来自:
<!-- language: lang-js -->
<input size="100" name="query" value="95743639846435911282201623368817149970231530745600716013851051418596093791193" type="text">
我的代码是:
<!-- language: lang-py -->
response3 = br.follow_link(nr=11) # follow the link
soup = BeautifulSoup(response3, "lxml") # read the page
for n in soup.findAll('input'): # find all <input >
print n['value'] # print the "value" of all <input >
我的代码现在正在打印all整个页面的<input>!
但我只想打印 first <input> 或带有 name="query" 的输入
【问题讨论】:
标签: python html get beautifulsoup mechanize