代码如下:
import requests
from bs4 import BeautifulSoup
ticker='FAST'
url = "https://www.google.com/search?q=nasdaq+%s+earnings+reaction+history&tbs=qdr:m"%(ticker)
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
# for searchs in soup.find_all('div', {'class':'BNeawe s3v9rd AP7Wnd'}):
cache = []
for searchs in soup.find_all('div', {'class':'kCrYT'}):
if searchs.find('a')['href'] is None: continue
cache.append(searchs.find('a')['href'])
print(''.join(cache))
当 .find('a')['href'] 没有返回结果时,我希望使用 if continue 语句来避免类型错误。然而,它并没有完成这项工作。有人可以指出克服它的方法吗?
翻阅古今
Smart猫小萌
胡说叔叔
相关分类