I've written a Python script to get some information(Price, in this case) from a website http://prixing.fr and then I wrote a function in VBA to publish it in my excel sheet.
It publishes the price in the Command Prompt but gives an error "#VALUE" in the Excel sheet.
Can somebody please tell me if there is a problem with the type of return I'm grabbing from the website and VBA?
The Python Code:
def prixing(CodeEAN):
from google import search
import urllib2
from bs4 import BeautifulSoup
query = raw_input("EAN or Nom de Produit: ") + " http://prixing.fr"
for url in search(query, num=1, start=0, stop=1, pause=1.0):
Pager = url
print url
page = urllib2.urlopen(Pager)
soup = BeautifulSoup(page)
Price1 = soup.find("div", attrs={'class':'prix'})
Price = repr([div.string for div in soup.findAll("div", 'prix')])
return Price
VBA Code:
Function Prixing(CodeEAN As String)
Set methods = PyModule("Methods", AddPath:=ThisWorkbook.Path)
Set result = Py.Str(Py.Call(methods, "prixing", CodeEAN))
Prixing = PyVar(result)
Exit Function
End Function
Thanking You,
Ashish
Last edit: Ashish Baid 2014-11-05
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well its a string so it should work all I can think of is that the string
is too long, I believe there is a limit on string length in excel try
truncating to understand if that's the problem... if so I can help you
figure out how to get around it
On 5 Nov 2014 16:29, "Ashish Baid" ashishbaid39@users.sf.net wrote:
Hello,
I've written a Python script to get some information(Price, in this case)
from a website http://prixing.fr and then I wrote a function in VBA to
publish it in my excel sheet.
It publishes the price in the Command Prompt but gives an error "#VALUE"
in the Excel sheet.
Can somebody please tell me if there is a problem with the type of return
I'm grabbing from the website and VBA?
The Python Code:
def prixing(CodeEAN):
from google import search
import urllib2
from bs4 import BeautifulSoup
query = raw_input("EAN or Nom de Produit: ") + " http://prixing.fr"for url in search(query, num=1, start=0, stop=1, pause=1.0):
Pager = url
print url
page = urllib2.urlopen(Pager)
soup = BeautifulSoup(page)
Price1 = soup.find("div", attrs={'class':'prix'})Price = repr([div.string for div in soup.findAll("div", 'prix')])
return Price
VBA Code:
Function Prixing(CodeEAN As String)
Set methods = PyModule("Methods", AddPath:=ThisWorkbook.Path)
Set result = Py.Str(Py.Call(methods, "prixing", CodeEAN))Prixing = PyVar(result)Exit Function
Thanks a lot for your response Eric.
I changed the code, sliced the string and tried to get A1 = prixing(5449000137609), i got the same #VALUE Error.
Here's the code:
Thanks again!
The Python Code:
def prixing(CodeEAN):
from google import search
import urllib2
from bs4 import BeautifulSoup
query = CodeEAN + " http://prixing.fr"
for url in search(query, num=1, start=0, stop=1, pause=1.0):
Pager = url
print url
page = urllib2.urlopen(Pager)
soup = BeautifulSoup(page)
Price1 = soup.find("div", attrs={'class':'prix'})
Price = repr([div.string for div in soup.findAll("div", 'prix')])
Prix = Price[21:25]
return Prix
VBA:
Function Prixing(CodeEAN As String)
Set methods = PyModule("videoload1", AddPath:=ThisWorkbook.Path)
Set result = PyCall(methods, "prixing", CodeEAN)
Prixing = PyVar(result)
Exit Function
End Function
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I've written a Python script to get some information(Price, in this case) from a website http://prixing.fr and then I wrote a function in VBA to publish it in my excel sheet.
It publishes the price in the Command Prompt but gives an error "#VALUE" in the Excel sheet.
Can somebody please tell me if there is a problem with the type of return I'm grabbing from the website and VBA?
The Python Code:
def prixing(CodeEAN):
from google import search
import urllib2
from bs4 import BeautifulSoup
query = raw_input("EAN or Nom de Produit: ") + " http://prixing.fr"
for url in search(query, num=1, start=0, stop=1, pause=1.0):
Pager = url
print url
page = urllib2.urlopen(Pager)
soup = BeautifulSoup(page)
Price1 = soup.find("div", attrs={'class':'prix'})
Price = repr([div.string for div in soup.findAll("div", 'prix')])
return Price
VBA Code:
Function Prixing(CodeEAN As String)
End Function
Thanking You,
Ashish
Last edit: Ashish Baid 2014-11-05
Well its a string so it should work all I can think of is that the string
is too long, I believe there is a limit on string length in excel try
truncating to understand if that's the problem... if so I can help you
figure out how to get around it
On 5 Nov 2014 16:29, "Ashish Baid" ashishbaid39@users.sf.net wrote:
Thanks a lot for your response Eric.
I changed the code, sliced the string and tried to get A1 = prixing(5449000137609), i got the same #VALUE Error.
Here's the code:
Thanks again!
The Python Code:
def prixing(CodeEAN):
from google import search
import urllib2
from bs4 import BeautifulSoup
query = CodeEAN + " http://prixing.fr"
for url in search(query, num=1, start=0, stop=1, pause=1.0):
Pager = url
print url
page = urllib2.urlopen(Pager)
soup = BeautifulSoup(page)
Price1 = soup.find("div", attrs={'class':'prix'})
Price = repr([div.string for div in soup.findAll("div", 'prix')])
Prix = Price[21:25]
return Prix
VBA:
Function Prixing(CodeEAN As String)
End Function
Maybe, the problem lies here:
Set result = PyCall(methods, "prixing", CodeEAN)
I believe there is a problem in passing the string argument "CodeEAN"
How do I pass such an argument from VBA to Python?
yes the code should be
Set result = PyCall(methods, "prixing", PyTuple(CodeEAN))
unless you're using excelpython version >= 2 in which case it's
Set result = Py.Call(methods, "prixing", Py.Tuple(CodeEAN))
On Thu, Nov 6, 2014 at 12:11 PM, Ashish Baid ashishbaid39@users.sf.net
wrote: