1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help Running Python Code

Discussion in 'Other Languages' started by SaraJ, Apr 3, 2011.

  1. SaraJ

    SaraJ Junior Member

    Joined:
    Jun 11, 2010
    Messages:
    172
    Likes Received:
    71
    Please excuse me as I don't have very much programming knowledge at all.

    I came across this script at

    http://blackcodeseo.com/writing-a-scraper/

    It's a simple scraper written in Python.

    My problem is that I don't know how to run the code. I'm not 100% sure what to do to make it work.

    I downloaded python and copy and pasted the code but nothing happens so I feel a bit clueless (and yes silly). :eek:

    Does anyone know how to actually execute the code?
     
  2. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    As long as you've pasted it into the Python IDLE editor, then there should be an option to run it, such as Run>Run Module or something similar. It's been a while since I've used it, but just look for an option to run it. Also make sure the code is up to date. There have been massive changes in Python.

    Edit: After looking at the code, it looks like you may need to download those packages it's trying to import, as I don't think they come bundled with Python. I can't tell you how to do that, as I'm not familiar with the latest releases of Python. But that code does look a bit old, as I at least know Python now requires semi-colons at the end of each line, whereas the older versions (like in that code) don't need semi-colons at the end of the lines. So you may need to either revert back to an older build of Python, or update that code to the latest one.
     
    • Thanks Thanks x 1
    Last edited: Apr 3, 2011
  3. SaraJ

    SaraJ Junior Member

    Joined:
    Jun 11, 2010
    Messages:
    172
    Likes Received:
    71
    Thanks for your reply.

    I think your observation that the code was from a different version of python is correct.

    I have version 2.something and this might be an older one. I didn't realize that this mattered that much but then again I don't know much about it.

    Typically I would turn the script into a filename.py and could run it but this wouldn't work at all.

    I appreciate your help.
     
  4. wu1239

    wu1239 Newbie

    Joined:
    Jun 4, 2011
    Messages:
    16
    Likes Received:
    0
    if you are using windows, after you install python, click python.exe

    >>> from urllib2 import urlopen
    you should input: "from urllib2 imort urlopen"

    and strings like this:u'Black Code SEO' is the output of the script.

    I could do some python work, if you have got some problem, just contact with me. I'm glad to help.
     
  5. thevil

    thevil Junior Member

    Joined:
    Aug 17, 2010
    Messages:
    190
    Likes Received:
    189
    save as script.py

    Im assuming youre in windows

    install python
    command prompt

    if youve set the necessary enviromental variables than
    > python script.py

    if not
    > CD DIR your way into your python dir, then >python c:\directorydownloaded\script.py
     
  6. other_henry

    other_henry Junior Member

    Joined:
    Jun 1, 2011
    Messages:
    107
    Likes Received:
    19
    Occupation:
    Freelance coder, server guy
    Location:
    US
    The code on that page will not execute as it is written, it has a bunch of garbage at the start of the lines.

    You need to strip out the '>>> ' at the beginnings of the lines.

    Also, a line like 'u'Black Code SEO'' is showing the result in unicode, it won't execute so strip it.

    I didn't test the rest of the code but it looks like a simple demo, beautiful soup is a really nice parser so it's worth learning.

    Once you get the code clean, save it as scrapper.py, on a linux box you will need to change the permissions so it will run.

    hth