抓取 requests.post 方法时出现错误
我正在尝试提取“德里”州办公室的数据。但是,我的代码无法正常工作。我确信我的 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/区域字段不可见,但对于某些州(如“德里”),选择“地区”字段后,会出现“PIN/区域”字段,我们需要选择适当的 PIN 码。从下拉列表中选择选项后,我们需要提交表单,它会为所选选项提供一个过滤表。
我正在尝试提取一个州某个地区的所有办公地址。请帮助我构建代码。如果你给我写代码,那么我会研究代码并了解我哪里出错了。否则,如果有任何关于通过网络形式发布方法进行此类网络抓取的研究材料,请告诉我。我会研究它们并再试一次。谢谢。
I am trying to extract the data for a state office in "DELHI'. However, my code is not working. I am sure the data parameters are incorrect in my python code. I have imported all the required libraries like pandas, beautifulSoup, requests etc before running the code.
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)
The website looks like this :
https://search.epfindia.gov.in/locate_office/office_location.php
In the form, there are a State/UT, District and PIN/Area field. Each State has respective districts. PIN/Area field is not visible, but for some States like "DELHI", after selecting District field, the PIN/Area field appears and we need to select appropriate PIN Code. After selecting the options from dropdown, we need to submit the form and it gives a filtered table for selected options.
I am trying to extract all the office address present in a districts of a State. Please help me building the code. If you write me the code, then I'll study the code and understand where I went wrong. Otherwise if there is any study material on such type of webscraping through web-form post method please tell me. I will study them and try again. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要获取特定 PIN 码的数据,您可以使用以下示例:
打印:
To get data for specific PIN you can use this example:
Prints: