跳到内容

KS3 计算机/项目创意/黑客应用程序/查找解决方案-查找数字

来自维基教科书,开放书籍,开放世界

1. 从 bbc 开始,以 ciphertechs 结束

[编辑 | 编辑源代码]
from selenium import webdriver

browser = webdriver.Firefox()
url = 'http://www.google.com'
browser.get(url)


答案

修改此代码
from selenium import webdriver

browser = webdriver.Firefox()
url = 'http://vicnum.ciphertechs.com/cgi-bin/guessnum1.pl'
browser.get(url)



2. 手动打开五次

[编辑 | 编辑源代码]

答案


from selenium import webdriver

browser = webdriver.Firefox()
url = 'http://vicnum.ciphertechs.com/cgi-bin/guessnum1.pl'
browser.get(url)

url = 'http://vicnum.ciphertechs.com/cgi-bin/guessnum1.pl'
browser.get(url)

url = 'http://vicnum.ciphertechs.com/cgi-bin/guessnum1.pl'
browser.get(url)

url = 'http://vicnum.ciphertechs.com/cgi-bin/guessnum1.pl'
browser.get(url)

url = 'http://vicnum.ciphertechs.com/cgi-bin/guessnum1.pl'
browser.get(url)



3. 打开五次(调用函数浏览器.get 五次,每次传递 url 参数)

[编辑 | 编辑源代码]

答案


from selenium import webdriver

browser = webdriver.Firefox()
url = 'http://vicnum.ciphertechs.com/cgi-bin/guessnum1.pl'
browser.get(url)
browser.get(url)
browser.get(url)
browser.get(url)
browser.get(url)



4. 打开五次(使用循环)

[编辑 | 编辑源代码]

答案


from selenium import webdriver

browser = webdriver.Firefox()

url    = 'http://vicnum.ciphertechs.com/cgi-bin/guessnum1.pl'
num = 0
while num < 5:
  browser.get(url)




5. 打开一次并在字段中输入值

[编辑 | 编辑源代码]

答案


from selenium import webdriver

browser = webdriver.Firefox()
url = 'http://vicnum.ciphertechs.com/cgi-bin/guessnum1.pl'
browser.get(url)

elem = browser.find_element_by_name('userguess')  # Find the search box
elem.send_keys(111)

form = browser.find_element_by_name('F')
form.submit()




6. 打开一次并在字段中输入 5 个值

[编辑 | 编辑源代码]

答案


from selenium import webdriver

browser = webdriver.Firefox()
url = 'http://vicnum.ciphertechs.com/cgi-bin/guessnum1.pl'
browser.get(url)

elem = browser.find_element_by_name('userguess')  # Find the search box
elem.send_keys(111)

form = browser.find_element_by_name('F')
form.submit()

elem = browser.find_element_by_name('userguess')  # Find the search box
elem.send_keys(112)

form = browser.find_element_by_name('F')
form.submit()

elem = browser.find_element_by_name('userguess')  # Find the search box
elem.send_keys(113)

form = browser.find_element_by_name('F')
form.submit()

elem = browser.find_element_by_name('userguess')  # Find the search box
elem.send_keys(114)

form = browser.find_element_by_name('F')
form.submit()

elem = browser.find_element_by_name('userguess')  # Find the search box
elem.send_keys(115)

form = browser.find_element_by_name('F')
form.submit()



7. 打开一次并使用函数输入值

[编辑 | 编辑源代码]

答案


from selenium import webdriver

browser = webdriver.Firefox()
url = 'http://vicnum.ciphertechs.com/cgi-bin/guessnum1.pl'
browser.get(url)

def try_Number (value):
  elem = browser.find_element_by_name('userguess')  # Find the search box
  elem.send_keys(value)

  form = browser.find_element_by_name('F')
  form.submit()

try_Number(111)



8. 打开一次并使用函数输入 5 个值

[编辑 | 编辑源代码]

答案


from selenium import webdriver

browser = webdriver.Firefox()
url = 'http://vicnum.ciphertechs.com/cgi-bin/guessnum1.pl'
browser.get(url)

def try_Number (value):
  elem = browser.find_element_by_name('userguess')  # Find the search box
  elem.send_keys(value)

  form = browser.find_element_by_name('F')
  form.submit()

try_Number(111)
try_Number(112)
try_Number(113)
try_Number(114)
try_Number(115)



8. 打开一次并使用函数和循环输入 5 个值

[编辑 | 编辑源代码]

答案


from selenium import webdriver

browser = webdriver.Firefox()
url = 'http://vicnum.ciphertechs.com/cgi-bin/guessnum1.pl'
browser.get(url)

def try_Number (value):
  elem = browser.find_element_by_name('userguess')  # Find the search box
  elem.send_keys(value)

  form = browser.find_element_by_name('F')
  form.submit()

num = 0
while num < 10:
  try_Number("00" + str(num))
  num += 1
华夏公益教科书