本文整理汇总了Python中mechanize.Browser.form['MozillaPager1$ddlPageNumber']方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.form['MozillaPager1$ddlPageNumber']方法的具体用法?Python Browser.form['MozillaPager1$ddlPageNumber']怎么用?Python Browser.form['MozillaPager1$ddlPageNumber']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mechanize.Browser
的用法示例。
在下文中一共展示了Browser.form['MozillaPager1$ddlPageNumber']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: range
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form['MozillaPager1$ddlPageNumber'] [as 别名]
########## STEP 3: Loop through each page in the result set ##########
output = []
for i in range(NUMBER_OF_PAGES):
########## GO TO THE PROPER PAGE ##########
# First we need to be sure we're on the correct page, which corresponds to
# the i in our for loop.
# We'll select the appropriate form, just like we did before.
br.select_form("ctl01")
# Now we just need to nagivate to the page corresponding to i and repeat the process
br.form['MozillaPager1$ddlPageNumber'] = [str(i)] # Typecast i to string
br.submit('MozillaPager1$btnPageNumber') # Use the bottom submit button!
########## GRAB AND PARSE THE HTML #########
# We'll grab and parse the HTML to get the appropriate table rows, just like we did before.
soup = BeautifulSoup(br.response())
results_table = soup.find('table', attrs={'id': 'grdEmployees'})
########## LOOP OVER ROWS AND CELLS ##########
# This is the same as the equivalent chunk in salaries-mechanize, only we're doing
# it for multiple pages, rather than just one.
for row in results_table.findAll('tr'):
output_row = []
示例2: range
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form['MozillaPager1$ddlPageNumber'] [as 别名]
# How many pages do you want to retrieve?
number_of_pages = 4
output_trs = []
for i in range(number_of_pages):
########## GO TO THE PROPER PAGE ##########
# First we need to be sure we're on the correct page, which corresponds to
# the i in our for loop.
# We'll select the appropriate form, just like we did before.
br.select_form("ctl01")
# Now we just need to nagivate to the page corresponding to i and repeat the process
br.form['MozillaPager1$ddlPageNumber'] = [str(i)]
br.submit()
########## GRAB AND PARSE THE HTML #########
# We'll grab and parse the HTML to get the appropriate table rows, just like we did before.
soup = BeautifulSoup(br.response())
employees = soup.find('table', id="grdEmployees")
rows = employees.findAll('tr')[1:]
########## LOOP OVER ROWS AND CELLS ##########
# This is the same as the equivalent chunk in salaries-mechanize, only we're doing
# it for multiple pages, rather than just one.
for tr in rows: