Advertisement
Advertisement
| 03.10.2008 at 07:06AM PDT, ID: 23228394 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
|
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
| Microsoft |
| Apple |
| Internet |
| Gamers |
| Digital Living |
| Virus & Spyware |
| Hardware |
| Software |
| ITPro |
| Developer |
| Storage |
| OS |
| Database |
| Security |
| Programming |
| Web Development |
| Networking |
| Other |
| Community Support |
| 03.10.2008 at 10:17AM PDT, ID: 21088257 |
| 03.10.2008 at 02:25PM PDT, ID: 21090607 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: |
#!/usr/bin/perl
use DBI;
# I HAD ONLY PostgreSQL, so you need to test this!
my $conn = DBI->connect("dbi:Pg:dbname=assets;host=localhost;port=5432", "postgres", "YOUWISH");
# my $conn = DBI->connect("dbi:mysql:dbname=YOUR_DATABASE;host=localhost", "YOUR_USER", "YOUR_PASS");
# delete everything from the history table
my $queryDelete = $conn->prepare("delete from history;");
$queryDelete->execute();
# print HTML from a URL
use LWP;
use HTML::TreeBuilder;
# the URL that we need to fetch and parse
my $url = "file:C:/bin/cygwin/home/adrpo/webpage-html/webpage.html";
# my $url = "http://your-host.org/file.html";
my $browser = LWP::UserAgent->new;
$response = $browser->get($url);
die "Can't get $url -- ", $response->status_line
unless $response->is_success;
die "Was expecting HTML, not ", $response->content_type
unless $response->content_type eq 'text/html';
# or whatever content-type you're equipped to deal with
my $tree = HTML::TreeBuilder->new; # empty tree
$tree->parse($response->content);
# dump the tree
# $tree->dump;
#get the body
@bodies = $tree->look_down('_tag' => 'body');
my ($co_name, $co_address, $co_telephone, $co_website,
$co_address1, $co_address2, $co_city, $co_state,
$co_postcode, $co_country);
foreach $body (@bodies) {
my @tags = $body->content_list();
my $i = 0;
$size = @tags;
while($i < $size) {
# get the Name: tag
if (ref($tags[$i]) eq "HTML::Element" and $tags[$i]->as_trimmed_text eq 'Name:')
{
$i++;
$co_name = $tags[$i];
}
$i++; # advance to Address: tag
if (ref($tags[$i]) eq "HTML::Element" and $tags[$i]->as_trimmed_text eq 'Address:')
{
$i++;
$co_address = $tags[$i];
if ($co_address =~ /(.+)\,\s(.+)\,\s([a-zA-Z]*)\s([0-9]*)\,\s(.+)/)
{
$co_address1 = $1;
$co_address2 = "";
$co_city = $2;
$co_state = $3;
$co_postcode = $4;
$co_country = $5;
}
else
{
print("Address: $co_address DID NOT MATCH!\n");
}
}
$i++; # advance to Telephone: tag
if (ref($tags[$i]) eq "HTML::Element" and $tags[$i]->as_trimmed_text eq 'Telephone:')
{
$i++;
$co_telephone = $tags[$i];
}
$i++; # advance to Website: tag
if (ref($tags[$i]) eq "HTML::Element" and $tags[$i]->as_trimmed_text eq 'Website:')
{
$i++;
$co_website = $tags[$i];
}
print "Inserting: ";
print "\t" . $co_name . "\n";
print "\t\t" . $co_address1 . " " . $co_address2 . " " . $co_postcode . ", " . $co_city . " ";
print $co_state . " " . $co_country . "\n";
print "\t\t" . $co_telephone . "\n";
print "\t\t" . $co_website . "\n";
my $queryInsert = $conn->prepare("insert into history(co_name, co_address1, co_address2, co_city, co_state, co_postcode, co_country, co_telephone, co_website) values(?, ?, ?, ?, ?, ?, ?, ?, ?)");
$queryInsert->execute($co_name, $co_address1, $co_address2, $co_city, $co_state, $co_postcode, $co_country, $co_telephone, $co_website);
$i++;
}
}
# check the inserted data
my $query = $conn->prepare("select * from history");
$query->execute();
while (@data = $query->fetchrow_array()) {
print "Name: $data[0]\n";
print "\tAddress 1: $data[1]\n";
print "\tAddress 2: $data[2]\n";
print "\tCity: $data[3]\n";
print "\tState: $data[4]\n";
print "\tPostcode: $data[5]\n";
print "\tCountry: $data[6]\n";
print "\tPhone: $data[7]\n";
print "\tWebsite: $data[8]\n";
}
print ("******* Done with the processing! ********\n");
|
| 03.12.2008 at 02:51PM PDT, ID: 21111169 |