首页 > 解决方案 > 如何从 10fastfingers 中提取我的打字数据?

问题描述

所以,我正在使用网站 10fastfingers.com,我想使用 Python 网络抓取从网站中提取我的打字数据。

https://10fastfingers.com/typing-test/english/ 这是网站的链接。在这里,您可以输入单词,直到计时器到期。然后它会给你分数。问题是当我尝试使用 requests 或 bs4 模块来提取我的打字数据时。它带来的是原始网站,而不是我填写表格后的网站。

原来的网站是这样的:

原网站

而且,在我进行打字测试后,它看起来像这样:

做打字测试后

现在,我想从第二个网站提取数据,即我的打字速度和准确性。我该怎么做?

我精通 python、pandas 和 numpy,但不擅长网络抓取。

标签: pythonweb-scraping

解决方案


该站点使用 Ajax 调用来发送用户击键数据并接收结果。此示例发送一些示例数据并解析结果:

import requests
from bs4 import BeautifulSoup

api_url = "https://10fastfingers.com/speedtests/auswertung"
headers = {"X-Requested-With": "XMLHttpRequest"}

# change this payload to your needs:
payload = {
    "sz": "1620825003874",
    "ez": "1620825063886",
    "wordlist": "life|think|can|got|too|what|land|earth|side|what|turn|between|book|car|quickly|not|leave|list|our|good|change|where|into|line|my|her|keep|other|such|say|not|her|soon|many|the|your|its|no|Indian|air|small|don't|second|city|different|sea|move|near|will|never|mean|there|such|also|something|spell|their|an|most|need|and|big|almost|miss|form|how|it's|add|group|let|stop|make|through|being|get|to|air|plant|around|try|just|face|men|eat|soon|great|work|very|good|city|move|this|much|to|idea|part|under|off|you|never|one|along|old|picture|being|let|might|now|people|went|example|even|old|family|begin|another|mile|great|Indian|second|us|home|did|thought|did|few|around|that|made|carry|hard|ask|talk|do|those|state|read|example|and|until|take|any|sentence|man|does|thing|carry|might|high|their|name|along|play|world|so|important|America|walk|this|to|it's|mother|large|feet|very|it|before|about|add|keep|use|run|away|old|every|out|down|might|you|find|small|still|idea|then|come|know|animal|Indian|thought|open|America|story|in|last|together|work|way|eat|hear|idea|tree|here|tell|may|work|food|he|should|way|place|be|question|important|next|just|thought|than|watch|country|leave|large|later|sound|until|give|but|use|left|as|animal|saw|here|day|large|be|water|want|question|way|father|over|said|of|face|land|began|something|house|group|line|word|are|turn|sea|form|sound|little|thing|but|by|boy|down|read|always|before|paper|into|leave|three|any|follow|side|has|through|at|white|walk|give|who|for|after|hard|world|hand|stop|want|kind|far|page|picture|again|well|thing|with|off|must|answer|right|have|about|got|run|found|air|play|will|world|go|or|almost|too|without|light|river|put|study|turn|oil|day|may|soon|without|or|where|mother|we|hear|is|through|watch|car|enough|close|cut|your|time|being|car|point|from|mo",
    "user_input": "life think got too what what land earth side what turn between book car quickly no leave list our good change where into line my her keep other such say her sonn many the your its no no Indioan air small don't second ",
    "backspace_counter": "5",
    "afk_timer": "1",
    "speedtest_id": "1",
    "mode": "",
}

data = requests.post(api_url, data=payload, headers=headers).json()
soup = BeautifulSoup(data["result"], "html.parser")

# print some data:
for row in soup.select("tr"):
    print(row.get_text(strip=True, separator=" "))

印刷:

33 WPM (words per minute)
Keystrokes ( 163 | 55 ) 218
Accuracy 73.09%
Correct words 31
Wrong words 12
Share on Facebook

推荐阅读