我如何刮擦“肯塔基州”一词。从整个页面?
每次我运行此代码时,它只会给我三遍数据,但我知道它在页面上会弹出更多次。
from bs4 import BeautifulSoup
import requests
url = 'https://www.nba.com/players'
result = requests.get(url)
doc = BeautifulSoup(result.text, 'lxml')
college = doc.find_all(text='Kentucky')
print(college)
Every time I run this code it only gives me the data three times but I know it pops up way more times on the page.
from bs4 import BeautifulSoup
import requests
url = 'https://www.nba.com/players'
result = requests.get(url)
doc = BeautifulSoup(result.text, 'lxml')
college = doc.find_all(text='Kentucky')
print(college)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为带有文本的Find_all将搜索精确的文本匹配。
有效的一个:
< option value =“ kentucky”> kentucky</option>
。无效:
<选项值=“ Western Kentucky”> Western Kentucky</option>
。如果您想找到所有发生的事件,则需要使用正则表达式。
检查 beautiful-soup-doc-doc 。还使用字符串而不是文本。
输出:
It is because find_all with text will search for exact text match.
Valid one:
<option value="Kentucky">Kentucky</option>
.No valid:
<option value="Western Kentucky">Western Kentucky</option>
.If you want to find all occurrences you need to use regular expressions.
Check beautiful-soup-doc. Also use string instead of text.
OUTPUT: