在 python 浏览器上获得太多结果

Getting too many result on python browser

朋友们,我想在 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 个元素,第二个有 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))