gpt4 book ai didi

python - 如何在不使用任何 yahoo api 的情况下使用 Python 在 yahoo 搜索引擎上进行基本查询?

转载 作者:行者123 更新时间:2023-12-01 06:00:50 29 4
gpt4 key购买 nike

我想使用 Beautiful Soup 和 urllib 从 python 脚本对雅虎搜索引擎进行基本查询。我对谷歌也做了同样的事情,这相当容易,但事实证明雅虎有点困难。查询雅虎搜索引擎的最小示例脚本会有所帮助。谢谢你!

最佳答案

首先,避免 urllib - 使用 requests相反,它是一个更加理智的界面。

然后,返回页面中的所有链接都具有类 yschttl 和遵循方案 link-1link-2 和很快。您可以与美丽的汤一起使用:

import requests
from bs4 import BeautifulSoup
url = "http://search.yahoo.com/search?p=%s"
query = "python"
r = requests.get(url % query)
soup = BeautifulSoup(r.text)
soup.find_all(attrs={"class": "yschttl"})

for link in soup.find_all(attrs={"class": "yschttl"}):
print "%s (%s)" %(link.text, link.get('href'))

给我们

Python Programming Language – Official Website (http://www.python.org/)
Python - Image Results (http://images.search.yahoo.com/search/images?_adv_prop=image&va=python)
Python (programming language) - Wikipedia, the free encyclopedia (http://en.wikipedia.org/wiki/Python_(programming_language))

还有更多。

关于python - 如何在不使用任何 yahoo api 的情况下使用 Python 在 yahoo 搜索引擎上进行基本查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10562180/

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