在Python中使用BeautifulSoup进行Web垃圾谷歌搜索

在Python中使用BeautifulSoup进行Web垃圾谷歌搜索,python,web-scraping,beautifulsoup,google-search-api,Python,Web Scraping,Beautifulsoup,Google Search Api,致力于一个自动化搜索几千个google搜索的项目,能够检查是否有“未找到结果”,并输入到数组中 使用BeautifulSoup,但我无法从URL导入HTML开始: from bs4 import BeautifulSoup import requests html = requests.get('www.lifehack.org') soup = BeautifulSoup(html,'html.parser') 软件包安装正常,但我发现错误: MissingSchema

致力于一个自动化搜索几千个google搜索的项目,能够检查是否有“未找到结果”,并输入到数组中

使用BeautifulSoup,但我无法从URL导入HTML开始:

from bs4 import BeautifulSoup
import requests

html = requests.get('www.lifehack.org')
soup = BeautifulSoup(html,'html.parser')
软件包安装正常,但我发现错误:

MissingSchema                             Traceback (most recent call last)
<ipython-input-28-8e881302fa25> in <module>
      1 from bs4 import BeautifulSoup
      2 import requests
----> 3 html = requests.get('www.lifehack.org')
      4 soup = BeautifulSoup(html,'html.parser')

C:\Program Files (x86)\Anaconda\lib\site-packages\requests\api.py in get(url, params, **kwargs)
     73 
     74     kwargs.setdefault('allow_redirects', True)
MissingSchema回溯(最近一次调用)
在里面
1来自bs4进口美化集团
2进口请求
---->3 html=requests.get('www.lifehack.org')
4 soup=BeautifulSoup(html,'html.parser')
get中的C:\Program Files(x86)\Anaconda\lib\site packages\requests\api.py(url、参数、**kwargs)
73
74 kwargs.setdefault('allow_redirects',True)
+还有很多类似的东西

我不知道如何解决这个问题。我希望能够快速地将HTML直接输入到程序中,而不必复制它并保存在本地HTML文件中


非常感谢您的帮助。

首先,您应该发布完整的错误消息,如果您只发布了部分错误消息,则无法解决问题

也就是说,有一件事可能会引起问题,那就是您的url需要完全限定

html = requests.get('http://www.lifehack.org')
事实上,如果您发布了执行代码时出现的全部错误,您可能会看到类似的情况,这会给出您的答案:

缺少架构:无效URL“www.lifehack.org”:未提供架构。 也许你的意思是

一旦解决了该问题,您将遇到另一个问题:

回溯(最近一次呼叫最后一次):

文件“”,第4行,在 soup=BeautifulSoup(html,'html.parser')

文件“C:\bs4\uuuu init\uuuuuu.py”, 第267行,在init
elif len(标记)你“搜索”了数千次?谷歌搜索?你考虑过用谷歌的API来代替吗?如果没有API,我通常使用BeautifulSoup一次性提取数据。你的问题可能与链接相关。您正在使用Python3吗?正如@Ant提到的,如果你试图自动化谷歌的搜索结果,你迟早会被谷歌的IP封锁,因为它侵犯了ToS。看看谷歌搜索API。
soup = BeautifulSoup(html.text,'html.parser')