当前位置: 首页>>代码示例>>Python>>正文


Python Browser.form['MozillaPager1$ddlPageNumber']方法代码示例

本文整理汇总了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 = []
开发者ID:sisiwei,项目名称:pycon-web-scraping-tutorial,代码行数:33,代码来源:04-salaries-full.py

示例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:
        
开发者ID:Chelwin,项目名称:scraping-class,代码行数:32,代码来源:salaries-full.py


注:本文中的mechanize.Browser.form['MozillaPager1$ddlPageNumber']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。