2017-09-25 122 views
0

我想從網站使用內置搜索功能,但我一直從主頁面獲取結果。不知道我做錯了什麼。無法使用網站搜索功能

import requests 
from bs4 import BeautifulSoup 


body = {'input':'ferris'} # <-- also have tried'query' 

con = requests.post('http://www.collegedata.com/', data=body) 

soup = BeautifulSoup(con.content, 'html.parser') 
products = soup.findAll('div', {'class': 'schoolCityCol'}) 

print(soup) 
print (products) 

回答

0

你在你的代碼2個問題:

  1. POST URL不正確。您應該更正此:

con = session.post('http://www.collegedata.com/cs/search/college/college_search_tmpl.jhtml', data=body)

  • 你的POST數據是不正確了。
  • body = {'method':'submit', 'collegeName':'ferris', 'searchType':'1'}

    您可以在任何瀏覽器(Chrome最好)使用的開發工具和檢查POST網址和數據頁。網絡。