Advertisement
Guest User

Untitled

a guest
Sep 4th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. for i in range(999):
  2. my_url = 'http://tis.nhai.gov.in/TollInformation?TollPlazaID=236'.format(i)
  3.  
  4. tbody = soup('table', {"class": "tollinfotbl"})[0].find_all('tr')[1:]
  5. TypeError: 'ResultSet' object is not callable
  6.  
  7. import csv
  8. import urllib.request
  9. import psycopg2
  10. from urllib.request import urlopen as uReq
  11.  
  12. from bs4 import BeautifulSoup as soup
  13.  
  14. conn = psycopg2.connect(database='--',user='--', password='--', port=--)
  15. cursor = conn.cursor()
  16.  
  17.  
  18.  
  19. for i in range(999):
  20. my_url = 'http://tis.nhai.gov.in/TollInformation?TollPlazaID=236'.format(i)
  21. uClient = uReq(my_url)
  22. page1_html = uClient.read()
  23. uClient.close()
  24. # html parsing
  25. soup = soup(page1_html, 'html.parser')
  26.  
  27.  
  28. tbody = soup('table', {"class": "tollinfotbl"})[0].find_all('tr')[1:]
  29. for row in tbody:
  30. cols = row.findChildren(recursive=False)
  31. cols = [ele.text.strip() for ele in cols]
  32. if cols:
  33. vehicle_type = str(cols[0])
  34. one_time = str(cols[1])
  35. return_type = str(cols[2])
  36. monthly_pass = str(cols[3])
  37. local_vehicle = str(cols[4])
  38.  
  39. query = "INSERT INTO toll (vehicle_type, one_time, return_type, monthly_pass, local_vehicle) VALUES (%s, %s, %s, %s, %s);"
  40. data = (vehicle_type, one_time, return_type, monthly_pass, local_vehicle)
  41. cursor.execute(query, data)
  42.  
  43. # Commit the transaction
  44. conn.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement