我的問題是一個由兩部分組成的問題,這引起了混亂。我試圖撰寫腳本來從 txt 檔案中提取搜索詞并單獨搜索每個詞。最佳答案將我引向正確的方向,并指出我在一次搜索 txt 檔案中的所有術語的代碼中出現錯誤。
我正在嘗試使用 Python 中的 Selenium 創建一個簡短的 Google 搜索自動化腳本。首先,我需要先創建 read txt 回圈。這是我目前的腳本:
with open('test.txt') as f:
for line in f:
print(line)
uj5u.com熱心網友回復:
只需通過測驗檔案并將每一行發送到搜索輸入標簽
with open('test.txt') as f:
for line in f:
driver.get("https://www.google.com/")
#identify search box
m = driver.find_element_by_name("q")
#enter search text
m.send_keys(line)
time.sleep(0.2)
#perform Google search with Keys.ENTER
m.send_keys(Keys.ENTER)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/391585.html
