【发布时间】:2020-04-08 09:46:11
【问题描述】:
我有以下 bs4 元素标签:
<span><span>some content</span> B</span>
字符串 B 的 len 未知(为简化起见,我将其命名为 B)
如何使用 beautifulSoup 提取 "b" ?或者我只是作为解决方案来提取文本,然后使用一些正则表达式技术
谢谢
编辑:完整代码
def get_doc_yakarouler(license_plate,url = 'https://www.yakarouler.com/car_search/immat?immat='):
response = requests.get(url+license_plate)
content = response.content
doc = BeautifulSoup(content,'html.parser')
result = doc.span.text
if 'identifié' in result :
return doc
else :
return f"La plaque {license_plate} n'est pas recensé sur yakarouler"
doc = get_doc_yakarouler('AA300AA')
span = doc.find_all('span')
motorisation_tag = span[1]
我要提取“1.6 TDI”
我使用以下方法找到了解决方案:motorisation_tag.text.replace(u'\xa0', ' ').split(' ')[1] 但我想直接使用 bs4 是否可行
【问题讨论】:
-
你能分享一些代码吗?
-
是的!完成了
-
@Doxcos44 看看下面的答案
标签: python html web-scraping beautifulsoup