我正在嘗試為“德里”中的州辦公室提取資料。但是,我的代碼不起作用。我確定我的 python 代碼中的資料引數不正確。我已經匯入了所有必需的庫,如 pandas、beautifulSoup、requests等在運行代碼之前。
r = requests.get('https://search.epfindia.gov.in/locate_office/office_location.php')
def get_all_forms(url):
soup = BeautifulSoup(r.content, "html.parser")
return soup.find_all('form')
details = {}
action = form.attrs.get("action").lower()
method = form.attrs.get("method", "get").lower()
State_value = "Delhi"
district_value = "East Delhi"
Pin_value = "110032"
inputs = [State_value, district_value, Pin_value]
fetchdata = requests.post(form, data = inputs)
print (fetchdata.text)
該網站如下所示: https ://search.epfindia.gov.in/locate_office/office_location.php
在表格中,有一個州/UT、地區和 PIN/地區欄位。每個州都有各自的區。PIN/Area 欄位不可見,但對于“DELHI”等一些州,在選擇 District 欄位后,會出現 PIN/Area 欄位,我們需要選擇適當的 PIN Code。從下拉串列中選擇選項后,我們需要提交表單,它會為所選選項提供一個過濾表。
我正在嘗試提取一個州某個地區的所有辦公地址。請幫助我構建代碼。如果你給我寫代碼,那么我會研究代碼并理解我哪里出錯了。否則,如果有任何關于通過網路表單發布方法進行此類網路抓取的學習材料,請告訴我。我會研究它們并再試一次。謝謝你。
uj5u.com熱心網友回復:
要獲取特定 PIN 的資料,您可以使用以下示例:
import requests
from bs4 import BeautifulSoup
post_url = "https://search.epfindia.gov.in/locate_office/resulttable.php"
data = {
"submit1": "submit1",
"state": "DELHI",
"district": "EAST DELHI",
"pin_area": "110032",
}
soup = BeautifulSoup(requests.post(post_url, data=data).content, "html.parser")
for td in soup.select("td.large_font"):
print(td.text)
印刷:
DSIIDC Facility Centre Building, Flatted Factory Complex,
2nd & 3rd Floor, Jhilmil Industrial Area,
New Delhi, DELHI
Email: [email protected]
Bhavishya Nidhi Bhawan, 8 th Floor, 28,Community Centre,
Wazirpur Industrial Area,
Delhi, DELHI
Email: [email protected]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/439593.html
