Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在不使用任何yahoo api的情况下使用Python在yahoo搜索引擎上进行基本查询?_Python - Fatal编程技术网

如何在不使用任何yahoo api的情况下使用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

我想使用BeautifulSoup和urllib从python脚本对yahoo搜索引擎进行基本查询。我也为谷歌做了同样的事情,这相当容易,但事实证明雅虎有点难。一个简单的雅虎搜索引擎查询示例脚本会有所帮助。谢谢大家!

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

然后,返回页面中的所有链接都具有类
yschttl
,并且在scheme
link-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('---------------------------------------------------')