我写了一个脚本来解析网页中的一些特定内容。内容是静态的,使用请求模块我可以访问它们。问题是,我希望获取的内容位于一些非常规格式的html元素中
我的脚本可以获取包含Mondays December 26th 2016 Horse Racing Tips
等的标题。单词Mondays
和年份2016
总是出现在每个标题中
现在,我想抓取不同比赛技巧下的内容,比如Sunshine Coast Race Tips
。每个Mondays
下有多个竞赛提示
其中一个比赛提示:
Sunshine Coast Race Tips:
Race 1: 7, 5, 4, 3 - Winner (1) $1.30 Exacta $1.90 Trifecta $4.10
Race 2: 2, 4, 3, 8 - Winner (1) $3.40 Exacta $62.70 Trifecta $116.10 First 4 $158.80
Race 3: 4, 10, 5, 13 - 2nd and 4th - Loss
这是我迄今为止的尝试:
import requests
from lxml.html import fromstring
url = "https://www.freehorseracingtipsaustralia.com/mondays-horse-racing-results-2016"
res = requests.get(url,headers={"User-Agent":"Mozilla/5.0"})
root = fromstring(res.text)
for item in root.xpath("//b[starts-with(.,'Mondays')]"):
print(item.text_content())
我怎样才能做到
尝试下面的代码获得比赛提示
相关问题 更多 >
编程相关推荐