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

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

使用 python 請求在網頁上搜索

使用 python 請求在網頁上搜索

MMMHUHU 2022-06-14 16:29:39
我想獲取網頁的 html 內容。我不確定如何定義搜索字段,我嘗試了以下方法。from fake_useragent import UserAgentimport requestsua = UserAgent()print(ua.chrome)header = {'User-Agent': str(ua.chrome)}print(header)body = {'Search': '1.1.1.1'}url = "https://randr.nist.gov/enzyme/Default.aspx"htmlContent = requests.get(url, data=body) print(htmlContent.text)有人可以建議如何定義正確的搜索字段嗎?
查看完整描述

1 回答

?
滄海一幻覺

TA貢獻1824條經驗 獲得超5個贊

可以像這樣使用 selenium 輕松完成:


from selenium import webdriver


search_input = '1.1.1.1'


driver = webdriver.Chrome('chromedriver.exe')

driver.get('https://randr.nist.gov/enzyme/Default.aspx')

driver.find_element_by_id('MainBody_txtSrchAutoFill').send_keys(search_input)

driver.find_element_by_id('MainBody_ImgSrch').click()

result_table = driver.find_element_by_id('MainBody_gvSearch')

print(result_table.text)


查看完整回答
反對 回復 2022-06-14
  • 1 回答
  • 0 關注
  • 176 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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