Created
October 14, 2015 21:34
-
-
Save pmolchanov/ebb032b99e536c0dea70 to your computer and use it in GitHub Desktop.
San Diego Fictitious Business Name search from the command line!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys, lxml.html, httplib, urllib, csv | |
# 0 - Business Name | |
# 1 - Owner Name | |
# 2 - File Number | |
query_type = urllib.quote(sys.argv[1]) | |
# e.g. "Promiscuous Fork" | |
query = urllib.quote(sys.argv[2]) | |
# Pulled from doing test queries against https://arcc.sdcounty.ca.gov/Pages/Fictitious.aspx | |
# with a query value of FOOBAR | |
body_templates = [ \ | |
'ctl00%24ScriptManager=ctl00%24m%24g_edc659ca_c734_4370_bfb7_526a87def9c5%24ctl00%24FBNUpdatePanel%7Cctl00%24m%24g_edc659ca_c734_4370_bfb7_526a87def9c5%24ctl00%24btnSearch&MSOWebPartPage_PostbackSource=&MSOTlPn_SelectedWpId=&MSOTlPn_View=0&MSOTlPn_ShowSettings=False&MSOGallery_SelectedLibrary=&MSOGallery_FilterString=&MSOTlPn_Button=none&__REQUESTDIGEST=0x50617A744C327DF47B3E69747912DE372526AAE6563CE27A8463791024111A941AC7C6D8F94D7EA030E64B10D9222C7AEB5FDDE6B2CC03AB430F4C6B940CE375%2C14%20Oct%202015%2021%3A19%3A01%20-0000&MSOSPWebPartManager_DisplayModeName=Browse&MSOSPWebPartManager_ExitingDesignMode=false&MSOWebPartPage_Shared=&MSOLayout_LayoutChanges=&MSOLayout_InDesignMode=&MSOSPWebPartManager_OldDisplayModeName=Browse&MSOSPWebPartManager_StartWebPartEditingName=false&MSOSPWebPartManager_EndWebPartEditing=false&_maintainWorkspaceScrollPosition=0&InputKeywords=Search%20this%20site...&ctl00%24PlaceHolderSearchArea%24ctl01%24ctl03=0&ctl00%24m%24g_edc659ca_c734_4370_bfb7_526a87def9c5%24ctl00%24ddlSearchBy=0&ctl00%24m%24g_edc659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8eEQV%2FAQiGzFwmUycO5GDXpcRsKX7PNlPz%2BYY%2B9W1L4PmTavTAN4zzQS4VZzWilx89qZnYmeTpjWXkjOmNd8FNcnTN%2BObqWQ0a3ORbPr%2FqSFs%2BU9HeUNkm6bfl9oJgm05ZRPgEjeN1caL2xC31MqGAB9qlijYPdHpojvOZ1wEZR49ezpFVkq6htcToScQQs6MnnS4t%2FvWrfFvbBSGlEAKVJtyPV3Rb4kH1rAfg%3D%3D&__VIEWSTATEENCRYPTED=&__EVENTVALIDATION=cmLtJ5xZSfUn3EQwRRM0a%2B2n4QDbrcnfvhnfUg8zeW7qXkKfVoh2smxAKoLqYsOxJeDXEZEnHS01RllGZtDYNg4uCUhocvADzNHlvPzr2ZVQdmCvzOHJLGeOeB5Twcexy4%2F1VMHHhTaoKoomvSwZ%2BTw0BLU%3D&_wpSelected=&_wzSelected=&__ASYNCPOST=true&ctl00%24m%24g_edc659ca_c734_4370_bfb7_526a87def9c5%24ctl00%24btnSearch=Search', \ | |
'ctl00%24ScriptManager=ctl00%24m%24g_edc659ca_c734_4370_bfb7_526a87def9c5%24ctl00%24FBNUpdatePanel%7Cctl00%24m%24g_edc659ca_c734_4370_bfb7_526a87def9c5%24ctl00%24btnSearch&MSOWebPartPage_PostbackSource=&MSOTlPn_SelectedWpId=&MSOTlPn_View=0&MSOTlPn_ShowSettings=False&MSOGallery_SelectedLibrary=&MSOGallery_FilterString=&MSOTlPn_Button=none&__REQUESTDIGEST=0xA164F11A39004D48F2FCE507B2C22E4492B77449BC1E30B5484F5AD9EB6018B4FEBE7DB6744667A1F3059B1CB506BD8D25DFC0FAA623D8176B4AB7D77B3CA410%2C14%20Oct%202015%2021%3A17%3A48%20-0000&MSOSPWebPartManager_DisplayModeName=Browse&MSOSPWebPartManager_ExitingDesignMode=false&MSOWebPartPage_Shared=&MSOLayout_LayoutChanges=&MSOLayout_InDesignMode=&MSOSPWebPartManager_OldDisplayModeName=Browse&MSOSPWebPartManager_StartWebPartEditingName=false&MSOSPWebPartManager_EndWebPartEditing=false&_maintainWorkspaceScrollPosition=0&InputKeywords=Search%20this%20site...&ctl00%24PlaceHolderSearchArea%24ctl01%24ctl03=0&ctl00%24m%24g_edc659ca_c734_4370_bfb7_526a87def9c5%24ctl00%24ddlSearchBy=1&ctl00%24m%24g_edc659ca_c734_4370_bfb7_526a87def9c5%24ctl00%24txtOwnerName=FOOBAR&__spText1=&__spText2=&_wpcmWpid=&wpcmVal=&__EVENTTARGET=&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=SwamHz2M4vlDU5xESDE%2BYzlhgnpp3zmU7%2Bp0rUy08dtMjFyaYzN4sGNn89LXjeesJp2Lg1OQPWQ6COOC7h9fbIaZ4pZgm%2F9cLwNpoEc%2BQ54cequlIaMCeMkUkluaWt9NyRsng%2FD6BQTtlxOqxf7GB3Klr3%2BNf0xHfDe23YtZLeSdO0Cpu1HPxTzgfbc%2FrPhoXVhD9ZLya8kWFSbq2hKv8DA5z1SjXbdICT5H7efUfTrYS6LnB3bKK1DxRY1xxmTuixmL1o7DXxCSep1DFGm8uGID4JS%2FezJ0EEbFuXyq2zB0OggHl8XM0DgQ0saHJ9xCpG8hLmmiwgMtoPpzu7DMdHwhRQXILMY%2FF7xT7nZHgWw4UQ1UcjM8Cf4LNq85xORdHpCXKCdkNY6Vwkjmpir18OsMq%2F910UVuC%2FFrDBRHo0fXeEurUV1NG3jvOw4%2FQto1pKt9fAg6IbiCAYmUcCF%2BWkZUjTcD97jU5HGgnXir6aVUfAJKF6opevl%2FJvEnTHeQpuGra3VeIMEfVl2FkFYIZNcMJ26fles8SdOyQi64eWa9MunUFfVayojcg0EW2JZ6KzBNaKmFwjWr2DGVsju%2BJReTna468daT1jZnHVCiEYOSKCxLpiKNwOikRR42QhajRaDz%2BvXm7ZqSrgYsHSaOXY6KkeECzRZxSEdq09xMLsiDaehnFhM%2FR61MPQpPE1CN7%2BTutVA5sXftoKqEtjbzHFWugl%2FihArvU6fwSvb%2BG%2B%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awg0er8XK%2ByBqLiKppq7%2F%2BdGTGThl4n%2Fxzs3zl6OISYvOAxAt3nYoxHg9qsLuNJ12tD4DNKV9GhQA7XeeC3H54A9%2FoaKeEw7PpbjtZDBeAV%2FXFpXV6dF4wS6XG%2BTW3u%2F3QOaGzetwUM8DaXkYnoaJhgtirQMVLDdo%2FozyYEFK68wndPtNi9h%2FglSzE8Yk1%2BYbgLXPNAvly%2Fe6auK3VwzZtjW6GmjXGsW8Sj3Y%2FVhieLthHEp%2Bbs%2Bfvcihb0O7RhzSCMBXVIKc1wfJeeB%2BnthSs0ffx%2FoFWYGGNUzeM3Fy4BlF%2BAGj8voFp%2FJ7CACyXRICJwwxt3ISYr3hL%2BPzhchcCo23vJZuK30jq1TlbrvU6A%3D%3D&__VIEWSTATEENCRYPTED=&__EVENTVALIDATION=dG3TJnf58GbWdMG1P%2FC8Wfam9R%2FBRz0d%2BihM8N8Nee9EPJUcGcFf%2BMP4qC%2FUrKW%2BBrZCC1k%2BN09NVlsveug3cNtcMGEtyjxJxRSO1JuoeFAjeKXbxOZhrIvNSARLek72eMg9KVygJXQ7R9lnTumhGf%2F51fo%3D&_wpSelected=&_wzSelected=&__ASYNCPOST=true&ctl00%24m%24g_edc659ca_c734_4370_bfb7_526a87def9c5%24ctl00%24btnSearch=Search', \ | |
'ctl00%24ScriptManager=ctl00%24m%24g_edc659ca_c734_4370_bfb7_526a87def9c5%24ctl00%24FBNUpdatePanel%7Cctl00%24m%24g_edc659ca_c734_4370_bfb7_526a87def9c5%24ctl00%24btnSearch&MSOWebPartPage_PostbackSource=&MSOTlPn_SelectedWpId=&MSOTlPn_View=0&MSOTlPn_ShowSettings=False&MSOGallery_SelectedLibrary=&MSOGallery_FilterString=&MSOTlPn_Button=none&__REQUESTDIGEST=0x3F6B60E9F6A82F752A43C2808320CCDF3A06323E41F680B08317CC1AEFBFEEF328C3616B552555269B997BC6E997C65878149FF2F7D76047C81D9C4CD352330D%2C14%20Oct%202015%2021%3A19%3A39%20-0000&MSOSPWebPartManager_DisplayModeName=Browse&MSOSPWebPartManager_ExitingDesignMode=false&MSOWebPartPage_Shared=&MSOLayout_LayoutChanges=&MSOLayout_InDesignMode=&MSOSPWebPartManager_OldDisplayModeName=Browse&MSOSPWebPartManager_StartWebPartEditingName=false&MSOSPWebPartManager_EndWebPartEditing=false&_maintainWorkspaceScrollPosition=0&InputKeywords=Search%20this%20site...&ctl00%24PlaceHolderSearchArea%24ctl01%24ctl03=0&ctl00%24m%24g_edc659ca_c734_4370_bfb7_526a87def9c5%24ctl00%24ddlSearchBy=2&ctl00%24m%24g_edc659ca_c734_4370_bfb7_526a87def9c5%24ctl00%24txtFileNum=FOOBAR&__spText1=&__spText2=&_wpcmWpid=&wpcmVal=&__EVENTTARGET=&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=gBtBUp7llSgxk2AuIe%2By76lp877de%2FraRHoi9IUXpgDdDDDoG%2Bm1DFuplJCnw3kF7OpdYEuywy4Y8jgBCpG6aR%2FSQS0ORORvwdwLQcIvOkmr%2Bp2006uIiWBbkFBke%2BBCLyxYKcsDyWm%2Fd9pNoX%2FGwzuF1oLIfmvWeENJRKcpzmccEHtkKy5b46pqCHpQGizsjeNcJ%2F0kD0hfZ8fRy8IgmmVgV6U8oTXLlNIXfQygVy3j4U8zvCmavMvZSTh229YIM0CE0E5PGV0tKZ4NLLCGMiaisOtC9TwUrx1cEqMM7CMnNfBtIgeJlezOfippqADG5zljaJ3Y6msjq%2F8XtGqd74lq%2BvRxaUksv3DARz5yCDImS3vrU6LZxF1OlM8CRzuSt02mQsn3IeHGGWM1npdV8RU7knw3AlwbnnhyfRnnvcBXsT3J1uZZBwwbMXrobcOhUbVqfEHv6ywD4CSdA9ApcLBiyyUji66bYrU31bokDngokkci1XEJUhRgoyvBM4%2F2ly5m%2Bt7%2B8bcZx%2B7eMO%2Ft6laZ4tIWOcysaERTGl8MMdnxi9nI41R2Wp3zdg4HXDyLV%2B0JDhPtxkDPmxyfIt2n%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PMUrwCsliMlYu5BH9zD%2BOOMdZoVov5vnWd3bJq4tctURHZ2BhqfgBxzDgvsYZajr1ZHsXswBxWNM8JuJWXev1lH6m0teTfFSxCLlxP9TC4GeAsPSbcwFOwbayStgzp6seVG7itoAiwhLvTMqMxDKfnndcUSSYd1P0mY0RdUtqHWIsDTLkdH6dD%2B9By9bGdAGHw9uHHaQ%2FtEjHoroYj5jDrWHPc4bIO5v5E8Y%2FG7KiFoLYVUuv6%2F7COTpGrOd415T%2BVrUkjTLPRmnqQTm%2BbE43ixkeXGgf%2Byut5SDt5R6m%2B14x9ZwzIoN9g9YzbCTRHFdE0bAsAFufHgQWDwQj88%2FmYS%2FW9nqcuH3QZjag%2Bivd8eKrI6Ygzyw%2F5Ef%2FOhIkjC5DAqIACA6rM3uwoFpgvCym9T7k0xgf2uIQsWDQ4JbEm8tvKNLgqBeKlWe%2FHAkMBYpGXKK3bbLPWeYOc%2BAkpCZdPbKrY6IL2PPZYH4kuPNHsPPVQSBCn%2FaxuFWkMS12lNOtVt6J8JDCn1WrM9pIkCQQ%3D%3D&__VIEWSTATEENCRYPTED=&__EVENTVALIDATION=Uj4FmKlcP5zhMZ%2BwjLLVr9T%2Fz5N5aspkrTr3Ingwy5hcCaopTPdWuCMedJPO2S%2FvE5jn0IyE08zRBDc5uddey8%2B72SReV4JlSus5%2F2Yq0Gaqt7B46gWLidFi6V5PefOLhlOKeLzXdtTPpopxlI81AxEhFHk%3D&_wpSelected=&_wzSelected=&__ASYNCPOST=true&ctl00%24m%24g_edc659ca_c734_4370_bfb7_526a87def9c5%24ctl00%24btnSearch=Search' | |
] | |
body = body_templates[int(query_type)] | |
body = body.replace('FOOBAR', query) | |
headers = {"User-Agent": "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)", "Content-Type": "application/x-www-form-urlencoded"} | |
conn = httplib.HTTPSConnection("arcc.sdcounty.ca.gov") | |
# conn.set_debuglevel(1) | |
conn.request("POST", "/Pages/fictitious.aspx", body, headers) | |
response = conn.getresponse() | |
response_data = response.read() | |
conn.close() | |
update_panel_html = lxml.html.fromstring(response_data); | |
search_result_rows = update_panel_html.xpath('//*[contains(@id,"gvSearchResults")]/tr[position()>1]') | |
if len(search_result_rows) < 1: | |
sys.stderr.write('No results\n') | |
sys.exit(1) | |
# TODO: handle more than 10 results (requires handling paged responses) | |
if len(search_result_rows) > 10: | |
sys.stderr.write('More than 10 results, showing only first 10\n') | |
del search_result_rows[10:] | |
writer = csv.writer(sys.stdout) | |
csv_header = ['Filing Number','Business Name','Owner Name','Filing Date'] | |
writer.writerow(csv_header) | |
for search_result_row in search_result_rows: | |
csv_row = [None] * 4 | |
csv_row[0] = search_result_row.xpath('./td[2]/a/text()')[0].strip() | |
csv_row[1] = search_result_row.xpath('./td[3]/text()')[0].strip() | |
csv_row[2] = search_result_row.xpath('./td[4]/text()')[0].strip() | |
csv_row[3] = search_result_row.xpath('./td[6]/text()')[0].strip() | |
writer.writerow(csv_row) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment