-1

Friends i want to extract live scores on espncricinfo i try with dryscrape :-

Import dryscrape as d
d.start_xvfb()
br = d.Session()
br.visit('http://www.espncricinfo.com/ci/engine/match/index.html?view=live')
for x in br.xpath('//*[@class = "innings-info-1"]'):
 x
#print 4 results 
for y in br.xpath('//*[@class = "innings-info-2"]'):
 y
#print 4 results of 2nd innings
#but when i try combian then print tooo many results
for x in br.xpath('//*[@class = "innings-info-1"]'):
 for y in br.xpath('//*[@class = "innings-info-2"]'):
  x,'\n',y
#need 4+4=8 results but python prints 16 results 

Please help me

Harry1992
  • 453
  • 1
  • 5
  • 12
  • i try with mechanize browse but failed to extract – Harry1992 Oct 30 '17 at 13:13
  • Then i try zip(x,y) and for i in enumerate(x); print x, '\n', y[i] but failed – Harry1992 Oct 30 '17 at 13:14
  • I'm not sure what you are expecting as an output. Why can't you just have separate `for` loops like you had before, instead of nesting them? Or you could do `for x, y in zip(br.xpath('//*[@class = "innings-info-1"]'), br.xpath('//*[@class = "innings-info-2"]')):` but that won't give you 8 results, you'll still only get 4 lines of printout. – roganjosh Oct 30 '17 at 13:20
  • Actually, I wasn't correct there, since you have `\n` in the `print` but then you end up with a strange misalignment in the output. – roganjosh Oct 30 '17 at 13:28
  • Thanks roganjosh – Harry1992 Oct 30 '17 at 13:59

1 Answers1

1

You have double loop. First have 4 elements, second 4 element. So you iterate 4 times by second loop and get 4 + 4 + 4 + 4 = 16. Your code execute the way it should.

if you want to get list of result you can for example do it like this:

x = [x for x in br.xpath('//*[@class = "innings-info-1"]')]
y = [y for y in br.xpath('//*[@class = "innings-info-2"]')]
print(list(zip(x,y))