不幸的是,我的 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")