【发布时间】:2021-02-17 15:34:12
【问题描述】:
我正在尝试编写一个程序来获取关键字列表并从用户输入的网站打印出包含此类单词的句子。现在我的输出正在打印出很多额外的东西,比如符号,我希望它只打印每次出现的句子。我该怎么做? 到目前为止的代码:
#Import Packages
import requests
from bs4 import BeautifulSoup
import urllib.request as ul
url = input('Enter URL:')
reg= requests.get(url,allow_redirects=False)
soup = BeautifulSoup(req.content, "lxml")
words = ["technology","wireless"]
for word in words:
print(word, soup.find(text=lambda text: text and word in text))
【问题讨论】:
标签: beautifulsoup python-requests keyword