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

标签 python pandas search ipython data-science

我正在学习数据科学,在解决问题时,我发现了一个奇怪的现象。问题是使用 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/

相关文章:

javascript - 如何在 Javascript 中使用 JSON 进行多维搜索?

python - 用 tweepy 发布推文

python - ML管道OneHotEncoder不适合

python - 在数据框的两列之间运行基本关联

search - sed:无法读取:没有这样的文件或目录

android - 如何在android项目中搜索方法或变量名?

python - Django 1.5 url 重定向与正则表达式?

javascript - 如何检查 {{message}} == "sometext"以显示特定图像

python - 索引中带有 nan 的 Pandas 数据框

python - 使用作为字符串一部分的整数迭代 for 循环