gpt4 book ai didi

Python正则表达式字符串排除

转载 作者:行者123 更新时间:2023-12-01 06:03:57 25 4
gpt4 key购买 nike

使用beautfiulsoup解析源代码进行抓取:

tempSite = preSite+'/contact_us/'
print tempSite
theTempSite = urlopen(tempSite).read()
currentTempSite = BeautifulSoup(theTempSite)
lightwaveEmail = currentTempSite('input')[7]

#<input type="Hidden" name="bb_recipient" value="comm2342@gmail.com" />

如何重新编译 lightwaveEmail 以便仅打印 comm2342@gmail.com?

最佳答案

有点错误的方式。其错误方式的原因是您使用编号索引来查找所需的标签 - BeautifulSoup 会根据标签或属性为您找到标签,这使其变得更加简单。

你想要类似的东西

tempSite = preSite+'/contact_us/'
print tempSite
theTempSite = urlopen(tempSite).read()
soup = BeautifulSoup(theTempSite)
tag = soup.find("input", { "name" : "bb_recipient" })
print tag['value']

关于Python正则表达式字符串排除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8979415/

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