【发布时间】:2021-09-12 05:30:00
【问题描述】:
嘿,我正在尝试抓取一个网站,并且输入中的某些值不会抓取为文本 仅 HTML 像这样
<input class="aspNetDisabled" disabled="disabled" id="ContentPlaceHolder1_EmpName" name="ctl00$ContentPlaceHolder1$EmpName" style="color:#003366;background-color:#CCCCCC;font-weight:bold;height:27px;width:150px;" type="text" value="John Doe"/>
所以我想做的只是获得价值(John Doe) 我试图 put.text 但它没有刮掉它 这是代码
soup=BeautifulSoup(r.content,'lxml')
for name in soup.findAll('input', {'name':'ctl00$ContentPlaceHolder1$EmpName'}):
with io.open('x.txt', 'w', encoding="utf-8") as f:
f.write (name.prettify())
【问题讨论】:
-
首先尝试在控制台中打印
name.prettify()并验证这是否是您期望的值。这将帮助您调试问题。 -
当我打印 name.prettify() 时,我得到的代码是上面的 HTML
标签: python web beautifulsoup screen-scraping