Created
December 11, 2019 21:30
-
-
Save varun93/580a0738a5cc35826751cd25fd608102 to your computer and use it in GitHub Desktop.
USCIS
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
import requests | |
from bs4 import BeautifulSoup | |
from datetime import datetime | |
def evaluate(): | |
filename = "{}.csv".format(datetime.today().strftime('%Y-%m-%d')) | |
fileHandle = open(filename, "a+") | |
url = 'https://egov.uscis.gov/casestatus/mycasestatus.do' | |
# initialize with the header | |
result = ["Receipt Number,Status,Date"] | |
for number in range(10000, 16000): | |
receiptNum = "YSC20900{}".format(number) | |
params = {"appReceiptNum" : receiptNum} | |
response = requests.post(url, data=params) | |
soup = BeautifulSoup(response.content.decode("utf-8"), 'lxml') | |
try: | |
title = soup.select(".appointment-sec h1")[0].getText() | |
date = " ".join(soup.select(".appointment-sec p")[0].getText().split(" ")[1:3])[:-1] | |
csvLine = ",".join([receiptNum, title, date]) | |
result.append(csvLine) | |
except: | |
print(receiptNum) | |
fileHandle.write("\n".join(result)) | |
fileHandle.close() | |
evaluate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment