Python 对于谷歌搜索结果的打印,BeautifulSoup并没有给出任何结果,尽管它的价值是存在的

Python 对于谷歌搜索结果的打印,BeautifulSoup并没有给出任何结果,尽管它的价值是存在的,python,beautifulsoup,google-search,Python,Beautifulsoup,Google Search,我想编写一个python代码,将一个查询作为用户的输入,并在google搜索该查询的前20页时打印Us 我的代码如下: print("Google Search") from googlesearch import search import requests import sys from bs4 import BeautifulSoup as BS import urllib.request word= input("E

我想编写一个python代码,将一个查询作为用户的输入,并在google搜索该查询的前20页时打印Us

我的代码如下:

print("Google Search")
from googlesearch import search                                  
import requests
import sys
from bs4 import BeautifulSoup as BS
import urllib.request 

word= input("Enter the word to be searched: ")

page='https://www.google.com/search?q='+word

for url in search(word):
    response = requests.get(page)
    soup=BS(response.text,'html.parser')
    a= soup.find('td',{'class':"cur"}).text.strip()
    if a==21:
       sys.exit()
    print(url)
错误全文如下:
我用硒做了同样的尝试,效果很好

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

print("Google Search")
word= input("Enter the word to be searched: ")


driver_path = 'C:\Windows\chromedriver.exe'
driver = webdriver.Chrome(executable_path=driver_path)
driver.get("http://www.google.com")
input_element = driver.find_element_by_name("q")
input_element.send_keys(word)
input_element.submit()


while(1):
    elems = driver.find_elements_by_class_name("TbwUpd")
    for elem in elems:
        b=elem.text.strip()
        print(b)

    num = driver.find_element_by_class_name('cur')
    a=num.text.strip()
    if a=="20":
        sys.exit()
    else:
        link = driver.find_element_by_link_text("Next").click()

我用硒做了同样的尝试,效果很好

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

print("Google Search")
word= input("Enter the word to be searched: ")


driver_path = 'C:\Windows\chromedriver.exe'
driver = webdriver.Chrome(executable_path=driver_path)
driver.get("http://www.google.com")
input_element = driver.find_element_by_name("q")
input_element.send_keys(word)
input_element.submit()


while(1):
    elems = driver.find_elements_by_class_name("TbwUpd")
    for elem in elems:
        b=elem.text.strip()
        print(b)

    num = driver.find_element_by_class_name('cur')
    a=num.text.strip()
    if a=="20":
        sys.exit()
    else:
        link = driver.find_element_by_link_text("Next").click()

你用什么词输入?根据搜索词的不同,该元素可能不存在。@CalebGoodman我输入了“Hi”一词,并在每个google搜索的导航表中出现。您使用了什么词作为输入?根据搜索词的不同,该元素可能不存在。@CalebGoodman我输入了“Hi”一词,并在每个google搜索的导航表中显示。