그래서 웹에서 일부 정보를 구문 분석하고 있습니다. 여기에 코드가 있습니다.효율적으로 구문 분석 된 텍스트를 분할하고 왼쪽 및 오른쪽 부분을 저장하는 방법
import lxml.html
from lxml.etree import XPath
url = "http://gbgfotboll.se/information/?scr=table&ftid=51168"
date = '2014-10-05'
rows_xpath = XPath("//*[@id='content-primary']/table[3]/tbody/tr[td[1]/span/span//text()='%s']" % (date))
time_xpath = XPath("td[1]/span/span//text()[2]")
team_xpath = XPath("td[2]/a/text()")
html = lxml.html.parse(url)
for i,row in enumerate(rows_xpath(html)):
#time = time_xpath(row)[0].strip()
team = team_xpath(row)[0]
print team
그리고 인쇄이 : 여기
Partille IF FK - Kode IF
IK Kongahälla - Romelanda UF
etc..
이 (제거 비 관련 부분) 위의 구문 분석 된 정보의 HTML 코드 :
<a href="?scr=result&fmid=2669197">Partille IF FK - Kode IF</a>
etc..
문자열을 분할하는 효율적인 방법이 있나요 그것을 파싱하면서? 분할은 "-"에서 발생하므로 왼쪽 부분과 오른쪽 부분을 저장합니다.
example string: Partille IF FK - Kode IF
string1 = Partille IF FK
string2 = Kode IF
아마도 구아바의'StringSplitter'를 시도해보십시오. https://www.google.com/url?hl=ko 2Fjavadoc는 2Fcom % 2Fgoogle % 2Fcommon % 2Fbase % 2FSplitter.html 및 EI = WT0nVP-6Kc3WigKCqoGwDA 및 USG = AFQjCNHzx86ZQhw9HamvJpS8y6pK5JlZww 및 SIG2 = wEtirp3clr9Ta8G_sFyJuA 및 BVM = bv.76247554는 d.cGE – sje397
+1 이유는 지상에서 이것은을 downvoted 하였다 %? – smci