私は Python を初めて使用し、不動産リスト Web サイト (www.realtor.ca) から情報を取得しようとしています。これまでのところ、次のコードを使用して MLS 番号をリストに集めることができました。
import urllib2, sys, re, mechanize, itertools, csv
# Set the url for the online search
url = 'http://www.realtor.ca/PropertyResults.aspx?Page=1&vs=Residential&ret=300&curPage=PropertySearch.aspx&sts=0-0&beds=0-0&baths=0-0&ci=Victoria&pro=3&mp=200000-300000-0&mrt=0-0-4&trt=2&of=1&ps=10&o=A'
content = urllib2.urlopen(url).read()
text = str(content)
# finds all instances of "MLS®: " to create a list of MLS numbers
# "[0-9]+" matches all numbers (the plus means one or more) In this case it's looking for a 6-digit MLS number
findMLS = re.findall("MLS®: [0-9]+", text)
findMLS = [x.strip('MLS®: ') for x in findMLS]
# "Page 1 of " precedes the number of pages in the search result (10 listings per page)
num_pages = re.findall("Page 1 of [0-9]+", text)
num_pages = [y.strip('Page 1 of ') for y in num_pages]
pages = int(num_pages[0])
for page in range(2,pages+1):
# Update the url with the different search page numbers
url_list = list(url)
url_list[48] = str(page)
url = "".join(url_list)
# Read the new url to get more MLS numbers
content = urllib2.urlopen(url).read()
text = str(content)
newMLS = re.findall("MLS®: [0-9]+", text)
newMLS = [x.strip('MLS®: ') for x in newMLS]
# Append new MLS numbers to the list findMLS
for number in newMLS:
findMLS.append(number)
私の MLS 番号のリスト (findMLS) を使用して、この Web サイトの上部にある MLS# 検索ボックスに各番号を入力したいと思います: http://www.realtor.ca/propertySearch.aspx
inspect 要素を使用すると、この検索ボックスを見つけることができますが、Python コードと Mechanize を使用してアクセスする方法がわかりません。
<input type="text" id="txtMlsNumber" value="" style="background-color:#ebebeb;border:solid 1px #C8CACA; " onkeypress="javascript:MLSNumberSearch(event)">
どんな助けでも大歓迎です。