Created
July 21, 2020 23:22
-
-
Save tetsupanda/90cbece0b21993c9bf5e7ab399c3c6c8 to your computer and use it in GitHub Desktop.
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
from http.client import HTTPSConnection | |
from html.parser import HTMLParser | |
class MYHTMLParser(HTMLParser): | |
def handle_starttag(self, tag, attrs): | |
if tag == 'a': | |
for name, value in attrs: | |
if name == "href": | |
print(name, "=", value) | |
def getSearchResults(city, searchstring): | |
rooturl = "{0}.craigslist.org".format(city) | |
paramurl = "/search/sss?query={0}&sort=rel".format(searchstring) | |
connection = HTTPSConnection(rooturl) | |
connection.request("GET", paramurl) | |
response = connection.getresponse() | |
print(response.status, response.reason) | |
responsebody = response.read().decode('utf-8') | |
return responsebody | |
parser = MYHTMLParser() | |
parser.feed(getSearchResults("indianapolis", "aeron")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment