Login Search

An introduction to research

Last Post
#211

Default

Simple Perl Web Parser Script
I don't mean any disrespect toward the original poster's preferred programming language. This is just another method. We all need options in life.
---------------------------------------------------------------
#! /usr/bin/perl
print "Content-type: text/html\n\n";

use LWP::Simple;

use HTML::TreeBuilder;

use HTML::FormatText;

$URL = get("http://www.websiteyouwanttoparse.com");

$Format = HTML::FormatText->new;

$TreeBuilder = HTML::TreeBuilder->new;

$TreeBuilder->parse($URL);

$Parsed = $Format->format($TreeBuilder);

print "$Parsed";
open(FILE, ">file.txt");
print FILE "$Parsed";
close(File);

exit;
--------------------------------------------------------------
Things you need to edit:
$URL = get("http://www.websiteyouwanttoparse.com");
Change the website name to a website you want to parse. If you know a little perl, those quotations have to be included.

and also edit
open(FILE, ">file.txt");
Change file.txt to a file name of your choice. Remember to change this every time you parse a new website or you'll have this program delete all the info on that file from a previous save.

This is my opinion. I take no responsibility for your actions. This is only for educational purposes.
Last edited by bobbydrake; 03-09-12 at 03:04 PM. Reason: format
#217

Default

thanks for all the useful info in this thread. it is a very good guide for the things i'm trying to learn.

currently i'm working through the python book recommended by the op. i have no previous coding experience, so it is slow but rewarding. i am having trouble opening a file in python though. here's the syntax of file "chaos.py"

Code: [View]
def main ():    print "this program illustrates chaotic function"
    x = input ("enter number btwn 0 and 1: ")
    for i in range (10):
        x = 3.9 * x * (1-x)
        print x
it runs just fine

Code: [View]
main ()this program illustrates chaotic function
enter number btwn 0 and 1: .4
0.936
0.2336256
0.698274248196
0.821680557759
0.571434313164
0.955098841721
0.16725167263
0.543186347468
0.96772626363
0.121805355011
but when i try to call it from the command line i get issues:

Code: [View]
python.chaos.py

Traceback (most recent call last):
File "", line 1, in 
python.chaos.py
NameError: name 'python' is not defined
or if i try calling just chaos.py, similar error message:

Code: [View]
Traceback (most recent call last):  File "", line 1, in 
    chaos.py
NameError: name 'chaos' is not defined
what am i doing wrong?
-----------------------------------------------------------------------
also my friend recommended i learn python using codeacademy. anybody have anything to say regarding whether codeacademy or the zelle book (the one in the op) is better, or what each is better for?
#219

Default

Quote Originally Posted by lecubs28 View Post
thanks for all the useful info in this thread. it is a very good guide for the things i'm trying to learn.

currently i'm working through the python book recommended by the op. i have no previous coding experience, so it is slow but rewarding. i am having trouble opening a file in python though. here's the syntax of file "chaos.py"

Code: [View]
def main ():    print "this program illustrates chaotic function"
    x = input ("enter number btwn 0 and 1: ")
    for i in range (10):
        x = 3.9 * x * (1-x)
        print x
it runs just fine

Code: [View]
main ()this program illustrates chaotic function
enter number btwn 0 and 1: .4
0.936
0.2336256
0.698274248196
0.821680557759
0.571434313164
0.955098841721
0.16725167263
0.543186347468
0.96772626363
0.121805355011
but when i try to call it from the command line i get issues:

Code: [View]
python.chaos.py

Traceback (most recent call last):
File "", line 1, in 
python.chaos.py
NameError: name 'python' is not defined
or if i try calling just chaos.py, similar error message:

Code: [View]
Traceback (most recent call last):  File "", line 1, in 
    chaos.py
NameError: name 'chaos' is not defined
what am i doing wrong?
-----------------------------------------------------------------------
also my friend recommended i learn python using codeacademy. anybody have anything to say regarding whether codeacademy or the zelle book (the one in the op) is better, or what each is better for?


Try python chaos.py

If that doesn't work, then check your PATH through Environment Variables (through control panel in System, Advanced Settings) and make sure Python is in the PATH: column.

Hope this helps.
#220

Default

Quote Originally Posted by CoverOne View Post
So I am completely unfamiliar with coding and programming, but is it actually possible to have a program automatically gather box score data and update daily saved into an excel file? If that's possible and relatively easy to learn, my betting habits may become much easier...
It's absolutely possible.