Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Web Scraping - Output File
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
smac2...@comcast.net  
View profile  
 More options Apr 26 2012, 1:54 pm
Newsgroups: comp.lang.python
From: SMac2...@comcast.net
Date: Thu, 26 Apr 2012 10:54:27 -0700 (PDT)
Local: Thurs, Apr 26 2012 1:54 pm
Subject: Web Scraping - Output File
Hello,

I am having some difficulty generating the output I want from web
scraping. Specifically, the script I wrote, while it runs without any
errors, is not writing to the output file correctly. It runs, and
creates the output .txt file; however, the file is blank (ideally it
should be populated with a list of names).

I took the base of a program that I had before for a different data
gathering task, which worked beautifully, and edited it for my
purposes here. Any insight as to what I might be doing wrote would be
highly appreciated. Code is included below. Thanks!

import os
import re
import urllib2

outfile = open("Skadden.txt","w")

A = 1
Z = 26

for letter in range(A,Z):

    for line in urllib2.urlopen("http://www.skadden.com/Index.cfm?
contentID=44&alphaSearch="+str(letter)):

            x = line
            if '"><B>' in line:
                    start=x.find('"><B>"')
                    end= x.find('</B></A></nobr></td>',start)
                    name=x[start:end]
                    outfile.write(name+"\n")
                    print name


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kiuhnm  
View profile  
 More options Apr 26 2012, 2:19 pm
Newsgroups: comp.lang.python
From: Kiuhnm <kiuhnm03.4t.yahoo.it>
Date: Thu, 26 Apr 2012 20:19:02 +0200
Local: Thurs, Apr 26 2012 2:19 pm
Subject: Re: Web Scraping - Output File
On 4/26/2012 19:54, SMac2...@comcast.net wrote:

You need
  alphaSearch=a
but you're using
  alphaSearch=1

>              x = line
>              if '"><B>' in line:

You should search for ' ><B>'.

>                      start=x.find('"><B>"')

Ditto.

>                      end= x.find('</B></A></nobr></td>',start)
>                      name=x[start:end]

You should use start+5 to skip ' ><B>'.

>                      outfile.write(name+"\n")
>                      print name

Your code is bound to break over and over (you should do some smarter parsing), but here's a working version:

--->
import os
import re
import urllib2

outfile = open("Skadden.txt","w")

A = ord('a')
Z = ord('z')

for letter in range(A, Z):
    for line in urllib2.urlopen("http://www.skadden.com/Index.cfm?contentID=44&alphaSearch="+chr(letter)):
            x = line
            if ' ><B>' in line:
                    start=x.find(' ><B>')
                    end= x.find('</B></A></nobr></td>',start)
                    name=x[start+5:end]
                    outfile.write(name+"\n")
                    print name
<---

Kiuhnm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
smac2...@comcast.net  
View profile  
 More options Apr 26 2012, 4:47 pm
Newsgroups: comp.lang.python
From: SMac2...@comcast.net
Date: Thu, 26 Apr 2012 13:47:00 -0700 (PDT)
Subject: Re: Web Scraping - Output File
On Apr 26, 2:19 pm, Kiuhnm <kiuhnm03.4t.yahoo.it> wrote:

Great, thanks so much for your help!

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »