代码:
# function - send a get request to each url
def send_get_request(link, search_for):
try:
html = send_request = requests.get(link)
for i in search_for:
if any(i in html.text for i in search_for):
return link
else:
return False
except Exception as e:
print("Error: " + str(e))
# search for any of these items
search_for = ['about me', 'home page']
在我的 search_for 列表项中查找时,如果找到关于一词,则将其标记为成功。我需要找到完整的单词,该单词与关于我和首页和首页相同。
答案 0 :(得分:0)
使用re.findall
import re
search_for = ['about me', 'home page', 'home']
def send_get_request(link, search_for):
try:
html = requests.get(link)
except requests.exceptions.RequestException as e:
print("Error: {}".format(e))
if re.findall('|'.join(search_for), html.text):
return html.text
else:
return False