我想知道這個人是否在另一所大學學習。我只是給了一個隨機的網站
from bs4 import BeautifulSoup
import requests
url = 'https://www.liverpool.ac.uk/environmentalsciences/staff/daniel-arribas-bel/'
r = requests.get(url)
soup = BeautifulSoup(r.content,'lxml')
print(soup.find(text='About').find_next('div').get_text().strip())'
現在通過列印有一個文本,但我想知道python中是否有一個函式可以讓你給大學說,如果它在文本中。
如果文本中有大學這個詞,我會搜索一個給出輸出的函式。
我希望輸出 YES、NO、TRUE 或 FALSE
uj5u.com熱心網友回復:
為您的網址獲取 404,認為您必須登錄
只需檢查是否university在抓取的文本中:
if 'university' in soup.find(text='About').find_next('div').get_text(strip=True):
print(True)
else:
print(False)
選擇:
if soup.find(text='About').find_next('div').get_text(strip=True).find('university') >= 0:
print (True)
else:
print(False)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/525869.html
上一篇:BeautifulSoupfindall獲取文本但回傳空
下一篇:回圈內的xpath未正確定位
