我正在嘗試搜索網頁(http://www.phillyhistory.org/historicstreets/)。我認爲相關的源html是這樣的:將值輸入到搜索欄並從網頁下載輸出
<input name="txtStreetName" type="text" id="txtStreetName">
你可以在網站上看到源html的其餘部分。我想進入那個文本框並輸入一個街道名稱並下載一個輸出(即在頁面的搜索框中輸入'Jefferson'並查看傑弗遜的歷史街道名稱)。我曾嘗試使用requests.post,並試圖在URL中嘗試輸入?get = Jefferson來測試如果沒有運氣的話。任何人有任何想法如何獲得此頁?謝謝,
卡梅倫說我現在嘗試(有些進口未使用的,因爲我打算解析等)
代碼:
import requests
from bs4 import BeautifulSoup
import csv
from string import ascii_lowercase
import codecs
import os.path
import time
arrayofstreets = []
arrayofstreets = ['Jefferson']
for each in arrayofstreets:
url = 'http://www.phillyhistory.org/historicstreets/default.aspx'
payload = {'txtStreetName': each}
r = requests.post(url, data=payload).content
outfile = "raw/" + each + ".html"
with open(outfile, "w") as code:
code.write(r)
time.sleep(2)
這沒有工作,只給了我下載的默認網頁(即傑弗森在搜索欄中沒有輸入和檢索。
嗨Dziugas,這正是我試過的。我沒有得到正確的輸出。我在這個問題上編輯了我的回答 – www3