Trouble finding any idea to perform reverse lookup using python



  • I've written some code to scrape "Address" and "Phone" against some shop names which is working fine. However, it has got two parameters to be filled in to perform it's activity. I expected to do the same from a csv file where "Name" will be in first column and "Lid" will be in second column and the harvested results will be placed across third and fourth column accordingly. At this point, I can't get any idea as to how I can perform the search from a csv file. Any suggestion will be vastly appreciated.

    import requests
    from lxml import html
    
    Names=["Literati Cafe","Standard Insurance Co","Suehiro Cafe"]
    Lids=["3221083","497670909","12183177"]
    for Name in Names:
    	for Led in Lids:
    		Page_link="https://www.yellowpages.com/los-angeles-ca/mip/"+"{0}".replace(" ","-")+"-"+"{1}".format(Name,Led)
    		response = requests.get(Page_link)
    		tree = html.fromstring(response.text)
    		titles = tree.xpath('//article[contains(@class,"business-card")]')
    		for title in titles:
    			Address= title.xpath('.//p[@class="address"]/span/text()')[0]
    			Contact = title.xpath('.//p[@class="phone"]/text()')[0]
    			print(Address,Contact)

  • administrators

    You can use the built-in CSV module in python to read values and write values accordingly - https://docs.python.org/2/library/csv.html



  • Thanks Ranjith, for your reply. I've already got it sorted.


Log in to reply
 

Looks like your connection to Codingislove Forum was lost, please wait while we try to reconnect.