Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for i in range(999):
- my_url = 'http://tis.nhai.gov.in/TollInformation?TollPlazaID=236'.format(i)
- tbody = soup('table', {"class": "tollinfotbl"})[0].find_all('tr')[1:]
- TypeError: 'ResultSet' object is not callable
- import csv
- import urllib.request
- import psycopg2
- from urllib.request import urlopen as uReq
- from bs4 import BeautifulSoup as soup
- conn = psycopg2.connect(database='--',user='--', password='--', port=--)
- cursor = conn.cursor()
- for i in range(999):
- my_url = 'http://tis.nhai.gov.in/TollInformation?TollPlazaID=236'.format(i)
- uClient = uReq(my_url)
- page1_html = uClient.read()
- uClient.close()
- # html parsing
- soup = soup(page1_html, 'html.parser')
- tbody = soup('table', {"class": "tollinfotbl"})[0].find_all('tr')[1:]
- for row in tbody:
- cols = row.findChildren(recursive=False)
- cols = [ele.text.strip() for ele in cols]
- if cols:
- vehicle_type = str(cols[0])
- one_time = str(cols[1])
- return_type = str(cols[2])
- monthly_pass = str(cols[3])
- local_vehicle = str(cols[4])
- query = "INSERT INTO toll (vehicle_type, one_time, return_type, monthly_pass, local_vehicle) VALUES (%s, %s, %s, %s, %s);"
- data = (vehicle_type, one_time, return_type, monthly_pass, local_vehicle)
- cursor.execute(query, data)
- # Commit the transaction
- conn.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement