Help Running Python Code

SaraJ

Junior Member
Joined
Jun 11, 2010
Messages
172
Reaction score
72
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). :o

Does anyone know how to actually execute the code?
 
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.
 
Last edited:
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.
 
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.
 
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
 
Please excuse me as I don't have very much programming knowledge at all.

snipDoes anyone know how to actually execute the code?

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
 
Back
Top