Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help to execute this code
#1
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
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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.
Reply
#4
So, you fixed the error but have a new problem?
Reply
#5
(Aug-26-2020, 12:21 AM)jefsummers Wrote: So, you fixed the error but have a new problem?

Yes.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020