Python漂亮的汤不起作用,如何在Google搜索中使用class ='st'刮取div,这是我的代码

问题描述 投票:0回答:1

结果值始终为空如何使用类st

在div内获取结果
 from bs4 import BeautifulSoup
  import requests

  response = requests.get("https://www.google.com/search?q=tom and jerry")
  soup = BeautifulSoup(response.text, 'html.parser')
  results = soup.find_all('div', class_='st')
  for text in headline_results:
    print(text) 
python-3.x
1个回答
0
投票

您是否尝试过查看response.text以确保该类确实存在div?

尝试print(response.text)或输出到文件并进行审查。

© www.soinside.com 2019 - 2024. All rights reserved.