Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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
使用Python从internet获取与给定关键字相关的所有URL_Python_Python 3.x_Web Scraping - Fatal编程技术网

使用Python从internet获取与给定关键字相关的所有URL

使用Python从internet获取与给定关键字相关的所有URL,python,python-3.x,web-scraping,Python,Python 3.x,Web Scraping,我正在用BeautifulSoup学习刮痧。我想做的是从互联网上获取与关键字相关的所有可用URL 有什么方法可以做到这一点吗?您可以使用请求python库在google上搜索。 通过pip安装请求安装请求 您可以使用google搜索任何内容,并使用Beautifulsoup解析结果。 下面的代码在google上搜索查询,然后使用BeautifulSoup获取google返回的URL import requests import urllib from bs4 import BeautifulSo

我正在用BeautifulSoup学习刮痧。我想做的是从互联网上获取与关键字相关的所有可用URL


有什么方法可以做到这一点吗?

您可以使用请求python库在google上搜索。 通过pip安装请求安装请求 您可以使用google搜索任何内容,并使用Beautifulsoup解析结果。 下面的代码在google上搜索查询,然后使用BeautifulSoup获取google返回的URL

import requests
import urllib
from bs4 import BeautifulSoup

query = 'any search term'


r = requests.get('https://www.google.com/search?q={}'.format(query))
soup = BeautifulSoup(r.text, "html.parser")
links = []
for item in soup.find_all('h3', attrs={'class' : 'r'}):
    links.append(item.a['href'])

print(links)

这个问题太宽泛了,无法回答。请阅读。另外,对于初学者来说,请看一下。这可能对你有帮助。