[英]Unable to Google Search Successfully with Selenium
我正在嘗試使用 Selenium 進行基本的谷歌搜索。這是非常基本的代碼,但它仍然沒有返回任何搜索結果
!pip install kora -q
from kora.selenium import wd
import time
from bs4 import BeautifulSoup as BS
def get_results(search_string):
url = 'https://www.google.com/'
wd.get(url)
time.sleep(3)
subject_box = wd.find_element_by_css_selector('input[name=q]')
subject_box.send_keys('search_string')
subject_box.submit()
time.sleep(3)
html2 = wd.page_source
print(html2)
get_results('dog')
我的 output 如下,我在任何地方都找不到搜索詞 dog - 不止於此,但你明白了:
Output 1:
Output 2:
關於為什么會發生這種情況的任何建議?
subject_box.send_keys('search_string')
改成
subject_box.send_keys(search_string)
你不是在傳遞變量,而只是傳遞一個字符串“search_string”,當引號被刪除時,它會傳遞變量中的值 dog
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.