如何在不使用任何yahoo api的情况下使用Python在yahoo搜索引擎上进行基本查询?
我想使用BeautifulSoup和urllib从python脚本对yahoo搜索引擎进行基本查询。我也为谷歌做了同样的事情,这相当容易,但事实证明雅虎有点难。一个简单的雅虎搜索引擎查询示例脚本会有所帮助。谢谢大家! 首先,避免使用如何在不使用任何yahoo api的情况下使用Python在yahoo搜索引擎上进行基本查询?,python,Python,我想使用BeautifulSoup和urllib从python脚本对yahoo搜索引擎进行基本查询。我也为谷歌做了同样的事情,这相当容易,但事实证明雅虎有点难。一个简单的雅虎搜索引擎查询示例脚本会有所帮助。谢谢大家! 首先,避免使用urllib-相反,它是一个更理智的界面 然后,返回页面中的所有链接都具有类yschttl,并且在schemelink-1、link-2之后有一个ID,依此类推。您可以在靓汤中使用: import requests from bs4 import BeautifulS
urllib
-相反,它是一个更理智的界面
然后,返回页面中的所有链接都具有类yschttl
,并且在schemelink-1
、link-2
之后有一个ID,依此类推。您可以在靓汤中使用:
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'))
给我们
以及更多。修改曼努埃尔的准则以使其生效:
url = "http://api.search.yahoo.com/search?p=%s"
query = 'Python'
r = requests.get(url % query)
soup = BeautifulSoup(r.text, features = "lxml")
soup.find_all(attrs={"class": "fz-ms lh-1_43x"})
for link in soup.find_all(attrs={"class": "fz-ms lh-1_43x"}):
print(link.text)
# print(link.text, link.get('href'))
print('---------------------------------------------------')
也许你可以把你的谷歌脚本作为一个起点。你的答案很有帮助,但据我所知,它缺少一行将值赋给
soup
。类似于soup=BeautifulSoup(r.text)
这似乎已经过时了。它不会返回任何您可以使用的结果,soup=BeautifulSoup(r.content,'html.parser')
url = "http://api.search.yahoo.com/search?p=%s"
query = 'Python'
r = requests.get(url % query)
soup = BeautifulSoup(r.text, features = "lxml")
soup.find_all(attrs={"class": "fz-ms lh-1_43x"})
for link in soup.find_all(attrs={"class": "fz-ms lh-1_43x"}):
print(link.text)
# print(link.text, link.get('href'))
print('---------------------------------------------------')