【发布时间】:2019-08-06 05:45:31
【问题描述】:
下面是我的代码。请检查并纠正我。
import requests
from bs4 import BeautifulSoup
url = ["https://www.tensorflow.org/","https://www.tomordonez.com/"]
the_word = input()
r = requests.get(url, allow_redirects=False)
soup = BeautifulSoup(r.content, 'lxml')
words = soup.find(text=lambda text: text and the_word in text)
print(words)
count = len(words)
print('\nUrl: {}\ncontains {} of word: {}'.format(url, count, the_word))
如何更改我的代码以解析多个 URL 并计算特定单词出现的次数?
【问题讨论】:
-
你的问题是什么?为什么你的代码不起作用?什么是预期的输出?请详细填写您的问题。
-
我想要通过多个 url 来计算特定单词的数量???该怎么做?
标签: python url web-scraping beautifulsoup