I'm using Google API and GSC to get the bold from the htmlSnippet:
from apiclient.discovery import build
from bs4 import BeautifulSoup
search_term="search term in Google"
api_key=""
resource=build("customsearch", 'v1', developerKey=api_key).cse()
result=resource.list(q=search_term,cx=' ').execute()
for i in result['items']:
html=str(i['htmlSnippet'])
print(html)
So I get something like this:
Metadescription from Google in <b>bolds text</b>. Here there is <b>another bold</b>
Then I try with this:
soup=BeautifulSoup(html,"lxml")
print(soup.find_all('b'))
And it works but I can't get only the text.
Trying with:
soup=BeautifulSoup(html,"lxml")
print(soup.find_all('b').text)
Doesn't work =/
Pleas help me!
soup.find_all()
返回一个列表,您需要在循环中获取每个列表的文本。
print(b.text for b in soup.find_all('b'))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.