Skip to content

Instantly share code, notes, and snippets.

@undefinedzain
Last active April 5, 2018 19:14
Show Gist options
  • Save undefinedzain/c46d6a99bf909814928554ab968308f3 to your computer and use it in GitHub Desktop.
Save undefinedzain/c46d6a99bf909814928554ab968308f3 to your computer and use it in GitHub Desktop.
Get resi data scraping
import requests
from bs4 import BeautifulSoup
import sys
if len(sys.argv) < 3:
print ('Usage example : python resi_scraping.py tiki 030003437484 ')
else:
jasa = sys.argv[1]
noresi = sys.argv[2]
headers = {
'User-Agent': 'Mozilla/5.0',
'Referer' : 'http://cariresi.com'
}
payload = {
'jasa':jasa,
'resi':noresi,
'cek' : ''
}
last_result = ''
session = requests.Session()
resp = session.post('http://cariresi.com',headers=headers,data=payload)
html_element = BeautifulSoup(resp.content,'lxml')
resi_detail_element = html_element.find('div', {'class' : 'table table-striped'})
resi_detail_table = resi_detail_element.find('table')
resi_table_tr = resi_detail_table.find_all('tr')
for element in resi_table_tr:
td = element.find_all('td')
new_1 = ''
for x in td:
new_1 += x.text + ' '
# print (new_1)
last_result += new_1+'\n'
# last_result += '#####'+'\n'
resi_journey_table = html_element.find('table',{'id':'tableku'})
resi_journey_tr = resi_journey_table.find_all('tr')
for element2 in resi_journey_tr:
td2 = element2.find_all('td')
new_2 = ''
for x2 in td2:
new_2 += x2.text+' '
# print (new_2)
last_result += new_2+'\n'
print last_result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment