-1

朋友们,我想在 espncricinfo 上提取实时比分,我尝试使用 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 

请帮我

4

1 回答 1

1

你有双循环。第一个有 4 个元素,第二个有 4 个元素。因此,您通过第二个循环迭代 4 次并得到 4 + 4 + 4 + 4 = 16。您的代码按应有的方式执行。

如果您想获取结果列表,例如可以这样做:

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))
于 2017-10-30T13:22:13.070 回答