def visa_select(visa_type, place, sid): proxies = g.value("proxies", None) cookies = copy.deepcopy(g.COOKIES) cookies["sid"] = sid # select immigrant/nonimmigrant visa select_visa_type_uri = "https://cgifederal.secure.force.com/selectvisatype" r = requests.get(select_visa_type_uri, cookies=cookies, proxies=proxies) if r.status_code != 200: return None soup = bs(r.text, "html.parser") view_state = soup.find(id="com.salesforce.visualforce.ViewState").get("value") view_state_version = soup.find(id="com.salesforce.visualforce.ViewStateVersion").get("value") view_state_mac = soup.find(id="com.salesforce.visualforce.ViewStateMAC").get("value") view_state_csrf = soup.find(id="com.salesforce.visualforce.ViewStateCSRF").get("value") data = { "j_id0:SiteTemplate:theForm": "j_id0:SiteTemplate:theForm", "j_id0:SiteTemplate:theForm:ttip": "Nonimmigrant Visa", "j_id0:SiteTemplate:theForm:j_id176": "继续", "com.salesforce.visualforce.ViewState": view_state, "com.salesforce.visualforce.ViewStateVersion": view_state_version, "com.salesforce.visualforce.ViewStateMAC": view_state_mac, "com.salesforce.visualforce.ViewStateCSRF": view_state_csrf } r = requests.post(select_visa_type_uri, data=data, cookies=cookies, proxies=proxies) if r.status_code != 200: return None # select place if place != "香港": select_post_uri = "https://cgifederal.secure.force.com/selectpost" r = requests.get(select_post_uri, cookies=cookies, proxies=proxies) if r.status_code != 200: return None soup = bs(r.text, "html.parser") view_state = soup.find(id="com.salesforce.visualforce.ViewState").get("value") view_state_version = soup.find(id="com.salesforce.visualforce.ViewStateVersion").get("value") view_state_mac = soup.find(id="com.salesforce.visualforce.ViewStateMAC").get("value") view_state_csrf = soup.find(id="com.salesforce.visualforce.ViewStateCSRF").get("value") contact_id = soup.find(id="j_id0:SiteTemplate:j_id112:contactId").get("value") place2id = { "北京": "j_id0:SiteTemplate:j_id112:j_id165:0", "成都": "j_id0:SiteTemplate:j_id112:j_id165:1", "广州": "j_id0:SiteTemplate:j_id112:j_id165:2", "上海": "j_id0:SiteTemplate:j_id112:j_id165:3", "沈阳": "j_id0:SiteTemplate:j_id112:j_id165:4" } place_code = soup.find(id=place2id[place]).get("value") data = { "j_id0:SiteTemplate:j_id112": "j_id0:SiteTemplate:j_id112", "j_id0:SiteTemplate:j_id112:j_id165": place_code, "j_id0:SiteTemplate:j_id112:j_id169": "继续", "j_id0:SiteTemplate:j_id112:contactId": contact_id, "com.salesforce.visualforce.ViewState": view_state, "com.salesforce.visualforce.ViewStateVersion": view_state_version, "com.salesforce.visualforce.ViewStateMAC": view_state_mac, "com.salesforce.visualforce.ViewStateCSRF": view_state_csrf } r = requests.post(select_post_uri, data=data, cookies=cookies, proxies=proxies) if r.status_code != 200: return None # select visa category select_visa_category_uri = "https://cgifederal.secure.force.com/selectvisacategory" r = requests.get(select_visa_category_uri, cookies=cookies, proxies=proxies) if r.status_code != 200: return None soup = bs(r.text, "html.parser") view_state = soup.find(id="com.salesforce.visualforce.ViewState").get("value") view_state_version = soup.find(id="com.salesforce.visualforce.ViewStateVersion").get("value") view_state_mac = soup.find(id="com.salesforce.visualforce.ViewStateMAC").get("value") view_state_csrf = soup.find(id="com.salesforce.visualforce.ViewStateCSRF").get("value") contact_id = soup.find(id="j_id0:SiteTemplate:j_id109:contactId").get("value") prefix = "j_id0:SiteTemplate:j_id109:j_id162:" category2id = { "B": {"北京": 0, "成都": 0, "广州": 0, "上海": 0, "沈阳": 0, "香港": 0}, "F": {"北京": 1, "成都": 1, "广州": 1, "上海": 1, "沈阳": 1, "香港": 1}, "O": {"北京": 4, "成都": 2, "广州": 3, "上海": 4, "沈阳": 2, "香港": 3}, "H": {"北京": 2, "广州": 3, "上海": 2, "香港": 3}, "L": {"北京": 3, "广州": 2, "上海": 3, "香港": 3} } category_code = soup.find(id=prefix + str(category2id[visa_type][place])).get("value") data = { "j_id0:SiteTemplate:j_id109": "j_id0:SiteTemplate:j_id109", "j_id0:SiteTemplate:j_id109:j_id162": category_code, "j_id0:SiteTemplate:j_id109:j_id166": "继续", "j_id0:SiteTemplate:j_id109:contactId": contact_id, "com.salesforce.visualforce.ViewState": view_state, "com.salesforce.visualforce.ViewStateVersion": view_state_version, "com.salesforce.visualforce.ViewStateMAC": view_state_mac, "com.salesforce.visualforce.ViewStateCSRF": view_state_csrf } r = requests.post(select_visa_category_uri, data=data, cookies=cookies, proxies=proxies) if r.status_code != 200: return None # select visa type select_visa_code_uri = "https://cgifederal.secure.force.com/selectvisacode" r = requests.get(select_visa_code_uri, cookies=cookies, proxies=proxies) if r.status_code != 200: return None soup = bs(r.text, "html.parser") view_state = soup.find(id="com.salesforce.visualforce.ViewState").get("value") view_state_version = soup.find(id="com.salesforce.visualforce.ViewStateVersion").get("value") view_state_mac = soup.find(id="com.salesforce.visualforce.ViewStateMAC").get("value") view_state_csrf = soup.find(id="com.salesforce.visualforce.ViewStateCSRF").get("value") type2id = { "F": 0, "B": 2, "H": 0, "O": 11 if place == "香港" else (7 if place == "广州" else 0), "L": 8 if place == "香港" else 2 } inputs = soup.find_all("input") type_codes = [x.get("value") for x in inputs if x.get("name") == "selectedVisaClass"] type_code = type_codes[type2id[visa_type]] data = { "j_id0:SiteTemplate:theForm": "j_id0:SiteTemplate:theForm", "j_id0:SiteTemplate:theForm:j_id178": "继续", "selectedVisaClass": type_code, "com.salesforce.visualforce.ViewState": view_state, "com.salesforce.visualforce.ViewStateVersion": view_state_version, "com.salesforce.visualforce.ViewStateMAC": view_state_mac, "com.salesforce.visualforce.ViewStateCSRF": view_state_csrf } r = requests.post(select_visa_code_uri, data=data, cookies=cookies, proxies=proxies) if r.status_code != 200: return None # update data update_data_uri = "https://cgifederal.secure.force.com/updatedata" r = requests.get(select_visa_code_uri, cookies=cookies, proxies=proxies) if r.status_code != 200: return None date = get_date(r.text) logger.info("%s, %s, SUCCESS_N, %s" % (visa_type, place, date)) if date: g.assign("status_%s_%s" % (visa_type, place), date) return date
def visa_select(visa_type, place, sid): proxies = g.value("proxies", None) cookies = copy.deepcopy(g.COOKIES) cookies["sid"] = sid # select immigrant/nonimmigrant visa select_visa_type_uri = "https://cgifederal.secure.force.com/selectvisatype" r = requests.get(select_visa_type_uri, cookies=cookies, proxies=proxies) if r.status_code != 200: print('visa_select 1: bad status code', r.status_code) return None soup = bs(r.text, "html.parser") view_state = soup.find( id="com.salesforce.visualforce.ViewState").get("value") view_state_version = soup.find( id="com.salesforce.visualforce.ViewStateVersion").get("value") view_state_mac = soup.find( id="com.salesforce.visualforce.ViewStateMAC").get("value") view_state_csrf = soup.find( id="com.salesforce.visualforce.ViewStateCSRF").get("value") data = { "j_id0:SiteTemplate:theForm": "j_id0:SiteTemplate:theForm", "j_id0:SiteTemplate:theForm:ttip": "Nonimmigrant Visa", # "j_id0:SiteTemplate:theForm:j_id176": "继续", "j_id0:SiteTemplate:theForm:j_id176": "Continue", "com.salesforce.visualforce.ViewState": view_state, "com.salesforce.visualforce.ViewStateVersion": view_state_version, "com.salesforce.visualforce.ViewStateMAC": view_state_mac, "com.salesforce.visualforce.ViewStateCSRF": view_state_csrf } r = requests.post(select_visa_type_uri, data=data, cookies=cookies, proxies=proxies) if r.status_code != 200: print('visa_select 2: bad status code', r.status_code) return None # select place # if place != "香港" and place != "台北": select_post_uri = "https://cgifederal.secure.force.com/selectpost" r = requests.get(select_post_uri, cookies=cookies, proxies=proxies) if r.status_code != 200: print('visa_select 3: bad status code', r.status_code) return None soup = bs(r.text, "html.parser") view_state = soup.find( id="com.salesforce.visualforce.ViewState").get("value") view_state_version = soup.find( id="com.salesforce.visualforce.ViewStateVersion").get("value") view_state_mac = soup.find( id="com.salesforce.visualforce.ViewStateMAC").get("value") view_state_csrf = soup.find( id="com.salesforce.visualforce.ViewStateCSRF").get("value") contact_id = soup.find( id="j_id0:SiteTemplate:j_id112:contactId").get("value") # NOTE: Place IDs are not unique; the first ID is simply the first one on the list place2id = { # "北京": "j_id0:SiteTemplate:j_id112:j_id165:0", # "成都": "j_id0:SiteTemplate:j_id112:j_id165:1", # "广州": "j_id0:SiteTemplate:j_id112:j_id165:2", # "上海": "j_id0:SiteTemplate:j_id112:j_id165:3", # "沈阳": "j_id0:SiteTemplate:j_id112:j_id165:4" "Melbourne": "j_id0:SiteTemplate:j_id112:j_id165:0", "Perth": "j_id0:SiteTemplate:j_id112:j_id165:1", "Sydney": "j_id0:SiteTemplate:j_id112:j_id165:2", } place_code = soup.find(id=place2id[place]).get("value") data = { "j_id0:SiteTemplate:j_id112": "j_id0:SiteTemplate:j_id112", "j_id0:SiteTemplate:j_id112:j_id165": place_code, # "j_id0:SiteTemplate:j_id112:j_id169": "继续", "j_id0:SiteTemplate:j_id112:j_id169": "Continue", "j_id0:SiteTemplate:j_id112:contactId": contact_id, "com.salesforce.visualforce.ViewState": view_state, "com.salesforce.visualforce.ViewStateVersion": view_state_version, "com.salesforce.visualforce.ViewStateMAC": view_state_mac, "com.salesforce.visualforce.ViewStateCSRF": view_state_csrf } r = requests.post(select_post_uri, data=data, cookies=cookies, proxies=proxies) if r.status_code != 200: print('visa_select 4: bad status code', r.status_code) return None # select visa category select_visa_category_uri = "https://cgifederal.secure.force.com/selectvisacategory" r = requests.get(select_visa_category_uri, cookies=cookies, proxies=proxies) if r.status_code != 200: print('visa_select 5: bad status code', r.status_code) return None soup = bs(r.text, "html.parser") view_state = soup.find( id="com.salesforce.visualforce.ViewState").get("value") view_state_version = soup.find( id="com.salesforce.visualforce.ViewStateVersion").get("value") view_state_mac = soup.find( id="com.salesforce.visualforce.ViewStateMAC").get("value") view_state_csrf = soup.find( id="com.salesforce.visualforce.ViewStateCSRF").get("value") contact_id = soup.find( id="j_id0:SiteTemplate:j_id109:contactId").get("value") prefix = "j_id0:SiteTemplate:j_id109:j_id162:" category2id = { # "B": {"北京": 0, "成都": 0, "广州": 0, "上海": 0, "沈阳": 0, "香港": 1, "台北": 1}, # "F": {"北京": 1, "成都": 1, "广州": 1, "上海": 1, "沈阳": 1, "香港": 0, "台北": 0}, # "O": {"北京": 4, "成都": 2, "广州": 3, "上海": 4, "沈阳": 2, "香港": 3, "台北": 3}, # "H": {"北京": 2, "广州": 3, "上海": 2, "香港": 3, "台北": 3}, # "L": {"北京": 3, "广州": 2, "上海": 3, "香港": 3, "台北": 3} "E": { "Melbourne": 5, "Perth": 0, "Sydney": 3 }, "F": { "Melbourne": 1, "Perth": 0, "Sydney": 0 }, } category_code = soup.find(id=prefix + str(category2id[visa_type][place])).get("value") data = { "j_id0:SiteTemplate:j_id109": "j_id0:SiteTemplate:j_id109", "j_id0:SiteTemplate:j_id109:j_id162": category_code, # "j_id0:SiteTemplate:j_id109:j_id166": "继续", "j_id0:SiteTemplate:j_id109:j_id166": "Continue", "j_id0:SiteTemplate:j_id109:contactId": contact_id, "com.salesforce.visualforce.ViewState": view_state, "com.salesforce.visualforce.ViewStateVersion": view_state_version, "com.salesforce.visualforce.ViewStateMAC": view_state_mac, "com.salesforce.visualforce.ViewStateCSRF": view_state_csrf } r = requests.post(select_visa_category_uri, data=data, cookies=cookies, proxies=proxies) if r.status_code != 200: print('visa_select 6: bad status code', r.status_code) return None # select visa type select_visa_code_uri = "https://cgifederal.secure.force.com/selectvisacode" r = requests.get(select_visa_code_uri, cookies=cookies, proxies=proxies) if r.status_code != 200: print('visa_select 7: bad status code', r.status_code) return None soup = bs(r.text, "html.parser") view_state = soup.find( id="com.salesforce.visualforce.ViewState").get("value") view_state_version = soup.find( id="com.salesforce.visualforce.ViewStateVersion").get("value") view_state_mac = soup.find( id="com.salesforce.visualforce.ViewStateMAC").get("value") view_state_csrf = soup.find( id="com.salesforce.visualforce.ViewStateCSRF").get("value") # Indices of the list of 'selectedVisaClass' values if place == 'Sydney': F_typecode = 0 E_typecode = -2 elif place == 'Perth': F_typecode = 3 E_typecode = -2 elif place == 'Melbourne': E_typecode = 0 F_typecode = 0 else: print('visa_select 8: unsupported place', place) return None type2id = {"F": F_typecode, "E": E_typecode} inputs = soup.find_all("input") type_codes = [ x.get("value") for x in inputs if x.get("name") == "selectedVisaClass" ] type_code = type_codes[type2id[visa_type]] data = { "j_id0:SiteTemplate:theForm": "j_id0:SiteTemplate:theForm", # "j_id0:SiteTemplate:theForm:j_id178": "继续", "j_id0:SiteTemplate:theForm:j_id178": "Continue", "selectedVisaClass": type_code, "com.salesforce.visualforce.ViewState": view_state, "com.salesforce.visualforce.ViewStateVersion": view_state_version, "com.salesforce.visualforce.ViewStateMAC": view_state_mac, "com.salesforce.visualforce.ViewStateCSRF": view_state_csrf } r = requests.post(select_visa_code_uri, data=data, cookies=cookies, proxies=proxies) if r.status_code != 200: print('visa_select 9: bad status code', r.status_code) return None # update data update_data_uri = "https://cgifederal.secure.force.com/updatedata" r = requests.get(update_data_uri, cookies=cookies, proxies=proxies) if r.status_code != 200: print('visa_select 10: bad status code', r.status_code) return None date = get_date(r.text) logger.info("%s, %s, SUCCESS_N, %s" % (visa_type, place, date)) if date: g.assign("status_%s_%s" % (visa_type, place), date) return date