【发布时间】:2017-10-30 13:10:04
【问题描述】:
朋友们,我想在 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
请帮帮我
【问题讨论】:
-
我尝试使用机械化浏览但提取失败
-
然后我尝试 zip(x,y) 和 for i in enumerate(x);打印 x, '\n', y[i] 但失败了
-
我不确定您期望的输出是什么。为什么不能像以前那样只使用单独的
for循环,而不是嵌套它们?或者您可以使用for x, y in zip(br.xpath('//*[@class = "innings-info-1"]'), br.xpath('//*[@class = "innings-info-2"]')):,但这不会给您 8 个结果,您仍然只能得到 4 行打印输出。 -
实际上,我的说法不正确,因为您在
print中有\n,但您最终会在输出中出现奇怪的错位。 -
谢谢罗根乔什
标签: python xpath printing xvfb dryscrape