python填网页表单_使用Python请求填写网站表单

当您发布请求时,您只是缺少了站点正在寻找的一个元素;当您实际使用intended form page时,表单包含一个submit按钮:

您需要在帖子数据中包含该按钮,因为站点使用该字段来检测您是否进行了实际搜索:

^{pr2}$

添加了这一项后,返回的页面包含查找的搜索结果:>>> import requests

>>> from bs4 import BeautifulSoup

>>> URL = 'https://www.acgov.org/ptax_pub_app/RealSearch.do'

>>> payload = {

... 'displayApn': '1-123-1',

... 'showHistory': 'y',

... 'searchBills': 'Search',

... }

>>> response = requests.post(URL, data=payload)

>>> soup = BeautifulSoup(response.content, 'lxml')

>>> for row in soup.select('#pplresultcontent3 tr'):

... text = row.get_text(': ', strip=True)

... if text: print(text)

...

Property Summary

APN: 1-123-1

Property Address: 424 M L KING JR WAY, OAKLAND 94607-3536

>>> for row in soup.select('#pplresultcontent4 tr'):

... text = row.get_text(' | ', strip=True)

... if text: print(text)

...

Tax Type | Bill Year | Tracer | Total Amount | Options

Installment | Due Date | Installment Amount | Status/Status Date

Secured | 2018-2019 | 01009500 | $8,773.64 | View Bill | Pay Bill

1st Installment | 12/10/2018 | $4,386.82 | Paid Oct 31, 2018

2nd Installment | 04/10/2019 | $4,386.82

在使用showHistory选项的capitalY之前,不会包括历史记录(pplresultcontent5表):>>> payload['showHistory'] = 'Y'

>>> response = requests.post(URL, data=payload)

>>> soup = BeautifulSoup(response.content, 'lxml')

>>> for row in soup.select('#pplresultcontent5 tr'):

... text = row.get_text(' | ', strip=True)

... if text: print(text)

...

Tax Type | Bill Year | Tracer | Total Amount | Options

Installment | Due Date | Installment Amount | Status/Status Date

Secured | 2017-2018 | 01009500 | $8,303.42 | View Bill

1st Installment | 12/10/2017 | $4,151.71 | Paid Dec 8, 2017

2nd Installment | 04/10/2018 | $4,151.71 | Paid Apr 6, 2018

Secured | 2016-2017 | 01009500 | $7,983.02 | View Bill

1st Installment | 12/10/2016 | $3,991.51 | Paid Dec 8, 2016

2nd Installment | 04/10/2017 | $3,991.51 | Paid Mar 30, 2017

Secured | 2015-2016 | 01009400 | $7,864.14 | View Bill

1st Installment | 12/10/2015 | $3,932.07 | Paid Dec 9, 2015

2nd Installment | 04/10/2016 | $3,932.07 | Paid Apr 8, 2016

Secured | 2014-2015 | 01009400 | $7,691.52 | View Bill

1st Installment | 12/10/2014 | $3,845.76 | Paid Dec 10, 2014

2nd Installment | 04/10/2015 | $3,845.76 | Paid Apr 7, 2015

Secured | 2013-2014 | 01009400 | $7,655.08 | View Bill

1st Installment | 12/10/2013 | $3,827.54 | Paid Dec 4, 2013

2nd Installment | 04/10/2014 | $3,827.54 | Paid Apr 9, 2014

Secured | 2012-2013 | 01009400 | $6,102.96 | View Bill

1st Installment | 12/10/2012 | $3,051.48 | Paid Dec 7, 2012

2nd Installment | 04/10/2013 | $3,051.48 | Paid Apr 8, 2013

Secured | 2011-2012 | 01009400 | $6,213.30 | View Bill

1st Installment | 12/10/2011 | $3,106.65 | Paid Dec 9, 2011

2nd Installment | 04/10/2012 | $3,106.65 | Paid Apr 10, 2012

Secured | 2010-2011 | 01069800 | $5,660.56 | View Bill

1st Installment | 12/10/2010 | $2,830.28 | Paid Dec 9, 2010

2nd Installment | 04/10/2011 | $2,830.28 | Paid Apr 10, 2011

Secured | 2009-2010 | 01070300 | $5,917.10 | View Bill

1st Installment | 12/10/2009 | $2,958.55 | Paid Dec 10, 2009

2nd Installment | 04/10/2010 | $2,958.55 | Paid Apr 10, 2010

Secured | 2008-2009 | 01070300 | $5,547.66 | View Bill

1st Installment | 12/10/2008 | $2,773.83 | Paid Dec 10, 2008

2nd Installment | 04/10/2009 | $2,773.83 | Paid Apr 10, 2009

Secured | 2007-2008 | 01069100 | $5,423.06 | View Bill

1st Installment | 12/10/2007 | $2,711.53 | Paid Dec 10, 2007

2nd Installment | 04/10/2008 | $2,711.53 | Paid Apr 10, 2008

Secured | 2006-2007 | 01069000 | $5,387.94 | View Bill

1st Installment | 12/10/2006 | $2,693.97 | Paid Dec 10, 2006

2nd Installment | 04/10/2007 | $2,693.97 | Paid Apr 10, 2007

Secured | 2005-2006 | 01069100 | $5,243.04 | View Bill

1st Installment | 12/10/2005 | $2,621.52 | Paid Dec 9, 2005

2nd Installment | 04/10/2006 | $2,621.52 | Paid Apr 10, 2006

Secured | 2004-2005 | 01068900 | $4,855.00 | View Bill

1st Installment | $2,427.50 | Paid Dec 10, 2004

2nd Installment | $2,427.50 | Paid Apr 10, 2005

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值