- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试从这个 ajax website 中提取数字上每个单元格的数据, 每个单元格的详细信息只有当鼠标指向单元格时才会弹出。
我已使用 Python selenium webdriver
和 phantomjs 加载和提取 page_source,但未找到数据。我使用 firebug 查找可能从中加载内容的任何 .json 文件,但没有找到。
请查看该网站,并建议我如何从指向 map 上每个单元格时移动的悬停框中的内容中抓取内容。
P.S:我在堆栈溢出和几个网站上做了很多研究,但都无济于事。
最佳答案
数据随手可得,您所需要做的就是好好看看幕后发生的事情。如何?使用 Developer Tool
并检查请求。您肯定会注意到有两个满足您的需求:
第一个以秒为单位使用当前时间,另一个以毫秒为单位。每次发出请求时都必须交换它。
bookies 请求是该站点所有 bookies 的映射。这就是我如何获得 1xBet
代码,即 417
。您可以轻松地将其与赔率数据进行映射,例如,以获取给定博彩公司和/或博彩公司的所有历史投注。这里有很多可能性。
赔率请求就是您在这些表格中看到的所有数据。
然后,您需要执行一些正则表达式来获取随这两个请求返回的 JSON
数据。
最后,您可以开始查看有效负载并获取您需要的内容。例如,假设您在 1xBet
和 X
列之后。所以你会期待这样的事情:
1xBet - 2.61 3.5 2.88
X
列的历史记录(此处的值为 3.5
)可能如下所示:
2020-10-18 05:03:45 - 3.58
2020-10-18 04:29:41 - 3.54
2020-10-18 02:53:17 - 3.56
2020-10-17 22:25:56 - 3.58
2020-10-17 17:13:53 - 3.60
2020-10-17 13:03:37 - 3.64
2020-10-17 10:12:06 - 3.66
and so on...
所以,将所有这些放在一起,这就是我想出的:
import json
import re
import time
from datetime import datetime
import requests
headers = {
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9,pl;q=0.8",
"referer": "https://www.oddsportal.com/",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.99 Safari/537.36"
}
def get_response(url: str) -> str:
return requests.get(url, headers=headers).text
time_now_s = int(time.time())
time_now_ms = int(round(time.time() * 1000))
bookies_js = f"https://www.oddsportal.com/res/x/bookies-201014103652-{time_now_s}.js"
odds_data_js = f"https://fb.oddsportal.com/feed/match/1-1-ld9FDhEI-1-2-yje1c.dat?_={time_now_ms}"
bookies = json.loads(re.findall(r'bookmakersData=({.*});var', get_response(bookies_js))[0])
odds_data = json.loads(re.findall(r"\.dat',\s({.*})", get_response(odds_data_js))[0])
bookie = bookies['417']['WebName'] # 417 is 1xBet's code
bookies_odds = odds_data['d']['oddsdata']['back']['E-1-2-0-0-0']['odds']['417'] # current odds for a bookie
odds_sorted = dict(sorted(bookies_odds.items())).values() # sorted as on the website 1 - X - 2
print(f"{bookie} - {' '.join(str(i) for i in odds_sorted)}")
history_columns = {
"1": "4ccecxv464x0xbcsm1", # 1 column
"2": "4ccecxv464x0xbcsm2", # 2 column
"X": "4ccecxv498x0x0", # X column
}
# odds history for the X column for a given bookie
history_data = odds_data['d']['history']['back'][history_columns['X']]['417']
for item in history_data:
value, _, timestamp = item
print(f"{datetime.fromtimestamp(timestamp)} - {value}")
输出:
1xBet - 2.61 3.5 2.88
2020-10-18 05:03:45 - 3.58
2020-10-18 04:29:41 - 3.54
2020-10-18 02:53:17 - 3.56
2020-10-17 22:25:56 - 3.58
2020-10-17 17:13:53 - 3.60
2020-10-17 13:03:37 - 3.64
2020-10-17 10:12:06 - 3.66
2020-10-17 09:58:04 - 3.64
2020-10-17 08:38:52 - 3.62
2020-10-17 08:08:54 - 3.64
2020-10-17 07:44:47 - 3.62
2020-10-17 06:17:33 - 3.64
2020-10-17 06:07:36 - 3.62
2020-10-17 00:04:35 - 3.64
2020-10-16 23:54:39 - 3.62
2020-10-16 23:38:40 - 3.64
2020-10-16 18:54:48 - 3.62
2020-10-16 15:14:17 - 3.64
2020-10-16 13:27:06 - 3.66
2020-10-01 21:43:39 - 3.40
这是您在 1xBet
网页上看到的列 X
上的值。
提示:如果您遇到missing oddsdata key
问题,请查看开发人员工具并查看端点是否已更改。看这个:
只需获取新的端点 https://fb.oddsportal.com/feed/postmatchscore/1-ld9FDhEI-yje1c.dat?_=
或更好地完成这部分 yje1c
部分并将其与代码中的部分交换。
关于python - 使用 Python 从 oddsportal.com 抓取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64393605/
如本answer所述,如果浏览器不支持 e,可以设置后备游标。 G。 光标:抓取;。我现在的问题是获取这些图像。在我的驱动器上本地搜索“.cur”只给了我系统光标,其中 grab.cur 和 grab
以下代码在计算机上运行以从 Instagram 帐户中抓取数据。当我尝试在 VPS 服务器上使用它时,我被重定向到 Instagram 登录页面,因此脚本不起作用。 为什么当我在电脑上或服务器上时,I
我在使用 Ruby 和 Mechanize 将 POST 查询传递到站点的网站上。访问站点的查询基于 firebug,如下所示 param.PrdNo=-1¶m.Type=Prop¶m
我正在尝试抓取一个具有多个页面结果的网站,例如“1、2、3、4、5...”。 每个分页号都是到另一个页面的链接,我需要抓取每个页面。 到目前为止,我想出了这个: while lien = page.l
我正在使用 HtmlAgilityPack 在 C# Asp.Net 中执行 Scraping,到目前为止,我在从多个 Web 执行 Scratch 时没有遇到问题,但是,尝试弹出以下代码时出现错误
如果我有一个 css 文件做这样的事情 #foo:after{content:"bar;} ,有没有办法用 javascript 获取 :after 的内容?获取父元素的内容只返回 #foo 元素的内
问题是这样的: 我有一个 Web 应用程序 - 一个经常更改的通知系统 - 在一系列本地计算机上运行。该应用程序每隔几秒刷新一次以显示新信息。计算机仅显示信息,没有键盘或任何输入设备。 问题是,如果与
我想制作一个程序来模拟用户浏览网站和点击链接。必须启用 Cookie 和 javascript。我已经在 python 中成功地做到了这一点,但我想把它写成一种可编译的语言(python ide 不会
我制作了这个小机器人,它通过搜索参数列表进行处理。它工作正常,直到页面上有几个结果: product_prices_euros 给出了一半为空的项目列表。因此,当我与 product_prices_c
我需要找到一个单词的匹配项,例如: 在网上找到所有单词“学习”https://www.georgetown.edu/(结果:4个字)(您可以看到它按CTRL + F并搜索) 我有我的 Python 代
有一个站点\资源提供一些一般统计信息以及搜索工具的界面。这种搜索操作成本高昂,因此我想限制频繁且连续(即自动)的搜索请求(来自人,而不是来自搜索引擎)。 我相信有很多现有的技术和框架可以执行一些情报抓
这并不是真正的抓取,我只是想在网页中找到类具有特定值的 URL。例如: 我想获取 href 值。关于如何做到这一点的任何想法?也许正则表达式?你能发布一些示例代码吗?我猜 html 抓取库,比如 B
我正在使用 scrapy。 我正在使用的网站具有无限滚动功能。 该网站有很多帖子,但我只抓取了 13 个。 如何抓取剩余的帖子? 这是我的代码: class exampleSpider(scrapy.
我正在尝试从这个 website 中抓取图像和新闻 url .我定义的标签是 root_tag=["div", {"class":"ngp_col ngp_col-bottom-gutter-2 ng
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭上个月。 Improve this ques
我在几个文件夹中有数千个 html 文件,我想从评论中提取数据并将其放入 csv 文件中。这将允许我为项目格式化和清理它。例如,我在这个文件夹中有 640 个 html 文件: D:\My Web S
我在编写用于抓取网页的实用程序时遇到了一个问题。 我正在发送 POST 请求来检索数据,我模仿我正在抓取的网络行为(根据使用 fiddler 收集的信息)。 我已经能够自动替换我的 POST 中除 V
对于 Googlebot 的 AJAX 抓取,我在我的网站中使用“_escaped_fragment_”参数。 现在我查看了 Yandex 对我网站的搜索结果。 我看到搜索结果中不存在 AJAX 响应
我正在尝试抓取网站的所有结果页面,它可以工作,但有时脚本会停止并显示此错误: 502 => Net::HTTPBadGateway for https://website.com/id/12/ --
我是一个学习网络爬虫的初学者,由于某种原因我无法爬网this地点。当我在 Chrome 中检查它时,代码看起来不错,但是当我用 BeautifulSoup 阅读它时,它不再是可刮的。汤提到“谷歌分析”
我是一名优秀的程序员,十分优秀!