gpt4 book ai didi

python - 不同环境下搜索结果不同

转载 作者:行者123 更新时间:2023-11-30 22:54:16 25 4
gpt4 key购买 nike

我正在学习数据科学,在解决问题时,我发现了一个奇怪的现象。问题是使用 python 打印 Beautiful Soup 主页上字符串“Soup”的出现次数。奇怪的是,iPython 笔记本和 Python 中出现的次数有所不同,当我在网页上进行手动搜索时,结果完全不同

如果有人能给出合理的解释,我会很高兴。我附上了代码片段和结果:

Python

I have simply used urllib and not BeautifulSoup

在 Pandas

Using the .count() function

手动

enter image description here

正如您所看到的,结果在所有环境中都有所不同,其中 Python 中出现了 39 次,Pandas 中出现了 41 次,手动搜索出现了 35 次。

谢谢

最佳答案

我认为Python仅找到39 ,因为2缺失在 <head> :

<title>Beautiful Soup: We called him Tortoise because he taught us.</title>
<meta name="Description" content="Beautiful Soup: a library designed for screen-scraping HTML and XML.">

您可以通过 Source of the page 查看- 有41发生次数。

如果检查webpage手动(出现 35 次),其中 4 次位于 urls 中和2<head> ,就这样在一起41 :

<a href="http://www.crummy.com/software/BeautifulSoup/bs3/documentation.html">Here's
the Beautiful Soup 3 documentation.</a>
<a href="download/3.x/BeautifulSoup-3.2.1.tar.gz">3.2.1</a>
<a href="/source/software/BeautifulSoup/index.bhtml">
<a href="http://www.crummy.com/software/BeautifulSoup/">

关于python - 不同环境下搜索结果不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37873759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com