【问题标题】:Unable to format the HTML output无法格式化 HTML 输出
【发布时间】:2018-05-02 23:04:30
【问题描述】:

我有返回 HTML 页面的 python 代码。在该页面中,有一行“2092 Pittman Road”是包裹地址。我的代码如下:

import mechanize
br = mechanize.Browser()
response = br.open("https://www.matsugov.us/myproperty")
for form in br.forms():
    if form.attrs.get('name') == 'frmSearch':
    br.form = form
    break
br.form['ddlType']=["taxid"]
br['txtParm']="218N02W27C003"
req=br.submit().read()
print req

req 给了我 HTML 格式的 o/p。您可以按原样运行此代码以查看 o/p。

【问题讨论】:

    标签: python html python-2.7 web-scraping


    【解决方案1】:

    将您的 HTML 输入到 BeautifulSoup,然后根据需要进行导航或格式化。

    【讨论】:

      【解决方案2】:

      使用此代码,这对你有用:

          from bs4 import BeautifulSoup
          import mechanize
          br = mechanize.Browser()
          response = br.open("https://www.matsugov.us/myproperty")
          for form in br.forms():
               if form.attrs.get('name') == 'frmSearch':
               br.form = form
               break
          br.form['ddlType']=["taxid"]
          br['txtParm']="218N02W27C003"
          req=br.submit().read()
          soup = BeautifulSoup(req, 'html.parser')
          table = soup.find('td', {'class': 'Grid_5'})
          for row in table:
               print row
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多