使用beautifulsoup解析抓取的源代码:
tempSite = preSite+'/contact_us/'
print tempSite
theTempSite = urlopen(tempSite).read()
currentTempSite = BeautifulSoup(theTempSite)
lightwaveEmail = currentTempSite('input')[7]
#<input type="Hidden" name="bb_recipient" value="[email protected]" />
如何重新编译lightwave Email,以便仅打印[email protected]?
最佳答案
金达走错路了。错误方法的原因是您使用编号索引来查找所需的标签-BeautifulSoup将根据标签或属性来为您找到标签,这使其变得更加简单。
你想要类似的东西
tempSite = preSite+'/contact_us/'
print tempSite
theTempSite = urlopen(tempSite).read()
soup = BeautifulSoup(theTempSite)
tag = soup.find("input", { "name" : "bb_recipient" })
print tag['value']