Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
您可以考虑在搜索短语上构建一个字典,然后将整个内容构建为这样的循环:
import requests from bs4 import BeautifulSoup urls = ['https://www.mannheimerswartling.se/medarbetare/', 'https://www.mannheimerswartling.se/medarbetare/hanne-aarsheim/', 'https://www.mannheimerswartling.se/medarbetare/sarmad-abdul-nabi/'] phrases = ["stockholms uni", "lunds uni", "uppsalas uni", "göteborgs uni", "örebros uni", "karlstads uni"] results = {} for url in urls: (r := requests.get(url)).raise_for_status() body = BeautifulSoup(r.content, 'lxml').body.text.lower() for phrase in phrases: results[phrase] = results.get(phrase, 0) + body.count(phrase) print(results)
输出:
{'stockholms uni': 1, 'lunds uni': 1, 'uppsalas uni': 0, 'göteborgs uni': 0, 'örebros uni': 0, 'karlstads uni': 0}
注意:
您需要在输出,但您应该明白
You could consider building a dictionary keyed on the search phrases then build the whole thing into a loop like this:
Output:
Note:
You'll need to do some work on the output but you should get the point
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(1)
您可以考虑在搜索短语上构建一个字典,然后将整个内容构建为这样的循环:
输出:
注意:
您需要在输出,但您应该明白
You could consider building a dictionary keyed on the search phrases then build the whole thing into a loop like this:
Output:
Note:
You'll need to do some work on the output but you should get the point