【发布时间】:2020-09-16 16:10:16
【问题描述】:
如果药物没有出现在谷歌搜索中,我正在尝试抓取谷歌知识面板以检索药物名称。例如,如果我在 Google 中查找“Buscopan”,出现的网页如下所示:
现在,我尝试对显示的代码执行的操作是在知识面板中使用术语“Scopolamina-N-butilbromuro”,但实际上在检查元素后无法在 html 代码中检索它。准确地说。我与错误信息一起实现的代码如下:
import requests
from bs4 import BeautifulSoup
网址
url = "https://www.google.com/search?client=safari&rls=en&q="+"buscopan"+"&ie=UTF-8&oe=UTF-8"
# Sending HTTP request
req = requests.get(url)
# Pulling HTTP data from internet
sor = BeautifulSoup(req.text, "html.parser")
temp = sor.find("h2", class_= "qrShPb kno-ecr-pt PZPZlf mfMhoc hNKfZe").text
print(temp)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-39-ef5599a1a1fc> in <module>
13 # Finding temperature in Celsius
14 #temp = sor.find("h2", class_='qrShPb').text
---> 15 temp = sor.find("h2", class_= "qrShPb kno-ecr-pt PZPZlf mfMhoc hNKfZe").text
16
17
AttributeError: 'NoneType' object has no attribute 'text'
我不知道我做错了什么。我认为我需要查看的 html 代码如下:
<h2 class="qrShPb kno-ecr-pt PZPZlf mfMhoc hNKfZe" data-local-attribute="d3bn" data-attrid="title" data-ved="2ahUKEwjujfLcgO7rAhWKjosKHSiBAFEQ3B0oATASegQIEBAL"></h2>
当然其余的html代码在报告的图片中,但是如果您需要更大的版本,请不要esitate!
有什么建议吗?
谢谢,
费德里科
【问题讨论】:
标签: python html web-scraping beautifulsoup