Menu

Webcrawling and importing to Excel - ExcelPython

2014-11-05
2014-11-07
  • Ashish Baid

    Ashish Baid - 2014-11-05

    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
    

    End Function

    Thanking You,

    Ashish

     

    Last edit: Ashish Baid 2014-11-05
    • Eric Reynolds

      Eric Reynolds - 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:

      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

      End Function

      Thanking You,

      Ashish

      Thanking You,

      Ashish

      Webcrawling and importing to Excel - ExcelPython
      https://sourceforge.net/p/excelpython/discussion/general/thread/6bff7814/?limit=25#79c9


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/excelpython/discussion/general/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
  • Ashish Baid

    Ashish Baid - 2014-11-06

    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

     
  • Ashish Baid

    Ashish Baid - 2014-11-06

    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?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.