我正在使用Python访问这个站点并清除HTML:http://forum.toribash.com/tori_spy.php
如您所见,如果您访问该网页,内容会在几秒钟内发生变化。这是一个页面,显示在一个论坛上最新的帖子,我正在做一个不和谐的机器人,将能够显示最新的帖子。你知道吗
现在,它显示列表中的第一个帖子,在任何动画/更改发生之前。你知道吗
我想知道是否有一种方法可以让我跳过动画或者让程序在访问后等待几秒钟,然后再获取所有的HTML。你知道吗
当前代码:
if message.content.startswith("-post"):
await client.send_message(message.channel, ":arrows_counterclockwise: **Accessing forums...**")
await client.send_typing(message.channel)
time.sleep(5)
#access site
session_requests = requests.session()
url = "http://forum.toribash.com/tori_spy.php"
result = session_requests.get(url,headers = dict(referer = url))
#access html
tree = html.fromstring(result.content)
list_stuff=[]
for atag in tree.xpath("//strong/a"): #search for <strong><a>
list_stuff.append(atag.text_content())
await client.send_message(message.channel, ":white_check_mark: Last post was in the thread **"+list_stuff[0]+"**")
非常感谢!你知道吗
页面使用
ajax
/xhr
加载新帖子。它使用这样的urllast
是最后一条消息的id,您可以在HTML
中找到它highestid = 9297850;
在某些<script>
标记中。r
似乎并不重要-至少代码在没有r
的情况下对我是有效的。你知道吗在获得
highestid
之后,您可以使用它来获得带有最新消息的XML
。你知道吗在
XML
中,您可以将它的ID看作<postid>
,这样您就可以在下一个请求中使用它。你知道吗当前结果(您的结果可能不同)
相关问题 更多 >
编程相关推荐