我试图解析的站点只有一个没有表单的输入框。我在定义单个输入框、传递地址然后提交时遇到了麻烦。
我想做的是输入一个地址,提交,获取下面的信息id="A18"
title="Click to get bulk trash pick up info"
并加载到 JSON 中。
Python:
import mechanicalsoup
# URL that we authenticate against
map_url = "http://mapservices.phoenix.gov/gis/imap/iMap.html"
address = "<address>"
json_file = "/home/pi/bulk_pickup.json"
# Setup browser
browser = mechanicalsoup.StatefulBrowser(
soup_config={'features': 'lxml'},
user_agent='Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13',
)
# Open the login URL
map_page = browser.get(map_url)
# Similar to assert login_page.ok but with full status code in case of failure.
map_page.raise_for_status()
search_form = mechanicalsoup.Form(map_page.soup.select_one('input[id="search_input"]'))
search_form.input({'search_input': address})