這個頁面有一個網址 https://www.example.com
<html>
<body>
<button id="button1" onclick=func1()>
<button id="button2" onclick=func2()>
</body>
<script>
function func1(){
open("/doubt?s=AAAB_BCCCDD");
}
function func2(){
open("/doubt?s=AABB_CCDDEE");
}
//something like that, it is working ....
</script>
</html>
AAAB_BCCCDD和AABB_CCDDEE - 兩者都是令牌......
我想用 python
我的 python 代碼獲取頁面中的第一個令牌-
import requests
r = requests.get("https://www.example.com")
s = r.text
if "/doubt?s=" in s:
# After this i can' understand anything ...
# i want to get the first token here as a variable
請幫我 ....
uj5u.com熱心網友回復:
通常,在獲取網站的原始文本內容后,您會首先使用像BeautifulSoup這樣的庫來決議 HTML 。它將創建一個檔案物件模型 (DOM) 樹,然后您可以查詢所需的元素。
但是,這不會讀取或解釋 JavaScript 代碼。對于您的問題,您可以使用正則運算式從原始文本中提取必要的資訊。
例子:
import re
import requests
r = requests.get("https://www.example.com")
s = r.text
pattern = re.compile('/doubt\\?s=(?P<token>\\w )')
matches = pattern.findall(s)
if len(matches) > 0:
print(matches[0])
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/398007.html
標籤:javascript Python html 蟒蛇请求
