Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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
如何打印URL';谷歌在python中的地位?_Python_Python 2.7 - Fatal编程技术网

如何打印URL';谷歌在python中的地位?

如何打印URL';谷歌在python中的地位?,python,python-2.7,Python,Python 2.7,我们如何在2.7版python中打印Google搜索结果中显示的URL 这是密码 domain = sys.argv[1]; print domain; test = [] test.append("aa") mainURL = "http://google.com/?q="; finalurl = mainURL + test[0] req = requests.get(finalurl) 启动请求后如何打印URL。获取(最终结果)?通常是: r = requests.get

我们如何在2.7版python中打印Google搜索结果中显示的URL

这是密码

domain = sys.argv[1];
print domain;
test = []

test.append("aa")    
mainURL = "http://google.com/?q=";

finalurl = mainURL + test[0]


req = requests.get(finalurl)
启动请求后如何打印URL。获取(最终结果)?通常是:

r = requests.get("url");
from bs4 import BeautifulSoup
soup = BeautifulSoup(r.text, 'html.parser')
soup.find_all("cite")
您可以查看网站的源代码(ctrl+U或开发工具/Inspector,并找到数据所在的标记/class/id。例如:
link…

现在的问题是,如果你看一下,输出:

print(soup.prettify())
然后你会看到,它们不仅仅会返回纯文本,而是用JS生成

  • 你可以看看其他搜索引擎的反应
  • 从python中更深入地挖掘Js代码执行(可能是其他LIB等?)
  • 请您考虑一下,有些人不会考虑在没有许可证的情况下,以程序形式大量地从其他网站解析数据。但我不知道谷歌在这方面的政策是什么
======= 编辑: @Rahul的链接是OP的最快解决方案。

查看库。选中此项,您需要解析结果。通常,人们通过一个名为。但是你需要了解一点HTML,并至少阅读库的快速入门,才能编写这段代码。@RahulKP我也这么做了,当我导入google模块时,它说找不到模块。即使我也用pip安装了它,你的URL是错误的,它是“google.com/search?q=”