How to create sequence worksheets in excel workbook by webscraping data according to website page number?
[/from bs4 import BeautifulSoup
from selenium import webdriver
import xlsxwriter
driver = webdriver.PhantomJS(executable_path =r'C:UsersHeronode_modulesphantomjs2libphantombinphantomjs.exe')
url = 'https://www.computerhope.com/jargon/a/a-0.htm'
driver.get(url)
# print driver.page_source
soup = BeautifulSoup(driver.page_source,'lxml')
c = soup.find('div', {'class' : 'container content'})
data_list=[]
for h in c.find_all("h1",{"itemprop":"headline"}):
pass
for p in c.find_all("p",{"class":"intro"}):
pass
#print(h.text,p.text)
data=[h.text,p.text]
data_list.append(data)
# Start from the first cell. Rows and columns are zero indexed.
row = 0
col = 0
# Create a workbook and add a worksheet.
workbook = xlsxwriter.Workbook('Expenses01.xlsx')
worksheet = workbook.add_worksheet('data_list')
for term, meaning in (data_list):
worksheet.write(row, col, term)
worksheet.write(row, col + 1, meaning)
row += 1
workbook.close()]
You must be logged in to post. Please login or register an account.