Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76147

Suitable Python code to scrape specific details from web pages.

X-Received by 10.182.110.130 with SMTP id ia2mr3585309obb.42.1407873630304; Tue, 12 Aug 2014 13:00:30 -0700 (PDT)
X-Received by 10.140.34.195 with SMTP id l61mr36172qgl.23.1407873630241; Tue, 12 Aug 2014 13:00:30 -0700 (PDT)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!h18no12253039igc.0!news-out.google.com!j6ni43193qas.0!nntp.google.com!v10no6563306qac.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Tue, 12 Aug 2014 13:00:30 -0700 (PDT)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=146.90.214.3; posting-account=59tTfwoAAACIDa2nz1oVlQJc3aCJi_5b
NNTP-Posting-Host 146.90.214.3
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <a8f10c4f-d4a0-48ed-ae92-2a43e9a094c3@googlegroups.com> (permalink)
Subject Suitable Python code to scrape specific details from web pages.
From Simon Evans <musicalhacksaw@yahoo.co.uk>
Injection-Date Tue, 12 Aug 2014 20:00:30 +0000
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Xref csiph.com comp.lang.python:76147

Show key headers only | View raw


Dear Programmers,
I have been looking at the You tube 'Web Scraping Tutorials' of Chris Reeves. I have tried a few of his python programs in the Python27 command prompt, but altered them from accessing data using links say from the Dow Jones index, to accessing the details I would be interested in accessing from the 'Racing Post' on a daily basis. Anyhow, the code it returns is not in the example I am going to give, is not the information I am seeking, instead of returning the given odds on a horse, it only returns a [], which isn't much use. 
I would be glad if you could tell me where I am going wrong. 
Yours faithfully
Simon Evans.
--------------------------------------------------------------------------------
>>>import urllib
>>>import re
>>>htmlfile = urllib.urlopen("http://www.racingpost.com/horses2/cards/card.sd?

race_id=600048r_date=2014-05-08#raceTabs=sc_")
htmltext = htmlfile.read()
regex = '<strong>1<a href="http://www.racingpost.com/horses/horse_home.sd?

horse_id=758752"onclick="scorecards.send(&quot;horse_name&quot:):return Html.popup(this,

{width:695,height:800})"title="Full details about this HORSE">Lively 

Baron</a>9/4F</strong><br/>'
>>>pattern = re.compile(regex)
>>>odds=re.findall(pattern,htmltext)
>>>print odds
[]
>>>
--------------------------------------------------------------------------------
>>>import urllib
>>>import re
>>>htmlfile = urllib.urlopen("http://www.racingpost.com/horses2/cards/card.sd?

>>>race_id=600048r_date=2014-05-08#raceTabs=sc_")
>>>htmltext = htmlfile.read()
>>>regex = '<a></a>'
>>>pattern = re.compile(regex)
>>>odds=re.findall(pattern,htmltext)
>>>print odds
[]
>>>
-------------------------------------------------------------------------------

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Suitable Python code to scrape specific details from  web pages. Simon Evans <musicalhacksaw@yahoo.co.uk> - 2014-08-12 13:00 -0700
  Re: Suitable Python code to scrape specific details from  web pages. Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-08-12 13:11 -0700
  Re: Suitable Python code to scrape specific details from  web pages. Roy Smith <roy@panix.com> - 2014-08-12 17:28 -0400
    Re: Suitable Python code to scrape specific details from  web pages. alex23 <wuwei23@gmail.com> - 2014-08-18 15:04 +1000
  Re: Suitable Python code to scrape specific details from  web pages. Simon Evans <musicalhacksaw@yahoo.co.uk> - 2014-08-12 15:44 -0700
    Re: Suitable Python code to scrape specific details from  web pages. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-13 10:04 +1000
      Re: Suitable Python code to scrape specific details from  web pages. Roy Smith <roy@panix.com> - 2014-08-12 20:30 -0400
    Re: Suitable Python code to scrape specific details from  web pages. Peter Pearson <ppearson@nowhere.invalid> - 2014-08-13 00:50 +0000
  Re: Suitable Python code to scrape specific details from  web pages. Denis McMahon <denismfmcmahon@gmail.com> - 2014-08-13 14:53 +0000

csiph-web