【问题标题】:Python Requests - Filling out FormsPython 请求 - 填写表格
【发布时间】:2018-02-15 00:16:34
【问题描述】:

在第一页上输入包裹代码后,我试图在网站上获取 html 代码。但是,下面的代码不起作用。我得到的只是https://treasurer.maricopa.gov/主页的HTML打印输出

输入504-27-095等包裹号后如何让python打印网站的结果?我需要结果页面中的 HTML。下面是我的代码。

import requests
payload = {'txtParcelNumBook': '504', 'txtParcelNumMap': '27', 'txtParcelNumItem': '095', 'txtParcelNumSplit' : ''}
website = "https://treasurer.maricopa.gov/"
r = requests.post(website, data=payload)
print (r.text)

【问题讨论】:

    标签: html python-3.x web-scraping python-requests


    【解决方案1】:

    如果您使用 Firefox 开发者工具中的浏览器控制台之类的工具,您可以看到发出的实际请求,在这种情况下,这表明实际访问的 URL 是 https://treasurer.maricopa.gov/Parcel/?Parcel=xxxyyzzz。

    所以你最好的选择是这样的:

    import requests
    payload = '504' + '27' + '095' # or whatever
    website = "https://treasurer.maricopa.gov/Parcel/?Parcel=" + payload
    r = requests.get(website)
    print(r.text)
    

    当然,在 IT 人员的另一轮轮换中,这可能会再次发生变化。

    【讨论】:

      猜你喜欢
      • 2017-03-10
      • 1970-01-01
      • 2014-05-29
      • 1970-01-01
      • 2018-05-22
      • 2012-05-16
      • 2017-02-07
      • 2019-10-17
      • 2014-04-13
      相关资源
      最近更新 更多