残念ながら、Python プログラムの実現に少し問題があります。ある時点で、私はそれ以上進むことができません。プログラムは次のことを行う必要があります。
- 検索エンジン「www.startpage.com」で特定のキーワードを自動検索します。
- 次に、結果を含むページを読み上げる必要があります (ここに問題があります)。
- プログラムは、特定の単語が検索結果のページに表示される頻度をカウントする必要があります。
ここでの問題は、検索結果ページからソース コードを取得できないことです。スタート ページのソース コードしか取得できません。解決策を知っている人はいますか?
前もって感謝します。
これまでのところ、私のプログラムは次のようになります。
import selenium.webdriver as webdriver
def get_results(search_term):
#this is the site, where I want to do the search
url="https://www.startpage.com"
browser = webdriver.Firefox()
browser.get(url)
search_box = browser.find_element_by_id("q")
#search in the search box after the search term
search_box.send_keys(search_term)
search_box.submit()
#print(browser.page_source) would give the result of the startpage (not the result page)
sub="dog"
print(source_code.count("dog"))
#counts zero times because it searchs for "dog" at the startpage
get_results("dog")