我正在寻找从谷歌搜索结果过滤文本(描述)。它包含在一个元素中。 我的工作如下:
result_div.find('span', attrs={'class': 'VwiC3b yXK7lf MUxGbd yDYNvb lyLwlc'})
其中result_div = soup.find_all('div', attrs={'class': 'g'})
但它返回一个空值
我怎样才能得到这个
我试过的代码:
driver.get('https://www.google.com')
s = driver.find_element_by_name('q')
s.send_keys("stackoverflow")
s.submit()
soup = BeautifulSoup(driver.page_source,'lxml')
result_div.find('span', attrs={'class': 'VwiC3b yXK7lf MUxGbd yDYNvb lyLwlc'})
有多个名为
g
的类,但并非所有类都包含嵌套类VwiC3b yXK7lf MUxGbd yDYNvb lyLwlc
。 由于您只需要描述,只需直接搜索类VwiC3b yXK7lf MUxGbd yDYNvb lyLwlc
:输出:
相关问题 更多 >
编程相关推荐