Python Forum

Full Version: Need help to execute this code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello

i need help to execute this web scrapping code in windows 10

from lxml import html
import requests
from bs4 import BeautifulSoup
import csv
from datetime import datetime
import xlsxwriter
quote_page = 'https://www.telecontact.ma/liens/imprimeurs/casablanca.php&page='
#csv_file=open('index.csv', 'w')
workbook = xlsxwriter.Workbook('imprimerie.xlsx')
worksheet = workbook.add_worksheet()
row = 0
col = 0
for j in range(1,9):
	page = requests.get(quote_page+str(j)).text
	soup = BeautifulSoup(page, 'html.parser')
	names = soup.find_all(id="resultats_h3_span")
	add=soup.find_all(itemprop="streetAddress")
	if len(add)<1:
		add=soup.find_all(itemprop="address")
	for i in range(len(add)):
		name=names[i].get_text()
		address=add[i].get_text()
		page2 = requests.get("https://www.telecontact.ma/"+names[i].find('a').get('href')).text
		soup2 = BeautifulSoup(page2, 'html.parser')
		tel = soup2.find(itemprop="telephone")
		tele=tel.get_text()
		worksheet.write(row, col,name)
		col+=1
		worksheet.write(row, col,address)
		col+=1
		worksheet.write(row, col,tele)
		row+=1
		col=0
workbook.close()
When i clicked to opened the file a black screen appeared and disappear in seconds with a message.

Thank you
don't run it by double click. open cmd and run it from there, from command line. this way you will see what the error is
(Aug-25-2020, 06:06 PM)buran Wrote: [ -> ]don't run it by double click. open cmd and run it from there, from command line. this way you will see what the error is

How can i fix this error?

Quote:Traceback (most recent call last):
File "imprimerie.py", line 1, in <module>
from lxml import html
ModuleNotFoundError: No module named 'lxml'

I installed the missing librairies, but there is one issue, the page i want to scrape the data from, have 567 results in total (29 pages), but the code only scrap 154 results.

I installed the missing librairies, but there is one issue, the page i want to scrape the data from, have 567 results in total (29 pages), but the code only scrap 154 results.
So, you fixed the error but have a new problem?
(Aug-26-2020, 12:21 AM)jefsummers Wrote: [ -> ]So, you fixed the error but have a new problem?

Yes.