亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何訪問鏈接并在其上停留特定的秒數?

如何訪問鏈接并在其上停留特定的秒數?

犯罪嫌疑人X 2023-10-05 16:46:55
我在停留在網站鏈接上時遇到問題,該鏈接有一個停留計時器,并且不會移動到其他地方。這是我的代碼:import requestsimport timefrom bs4 import BeautifulSoupurl = input('Please enter your link: ')def get_response(url, method='GET'):    response = requests.request(method, url, headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win32; x86) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"}, timeout=15)    text_response = response.text    status_code = response.status_code    return[status_code, text_response]while True:    (status_code, text_response) = get_response(url)    parse_data = BeautifulSoup(text_response, 'html.parser')    time.sleep(20)    print('done')    exit()該鏈接將打開,但不像在瀏覽器中那樣
查看完整描述

1 回答

?
蕪湖不蕪

TA貢獻1796條經驗 獲得超7個贊

計時器在網站上的 Javascript 代碼上運行,requests庫不運行網站的 Javascript 代碼。

使用Selenium代替,它允許您控制瀏覽器并運行網站的 Javascript。


查看完整回答
反對 回復 2023-10-05
  • 1 回答
  • 0 關注
  • 109 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號