【问题标题】:Not able to scrape data from website using BeautifulSoup in python无法在 python 中使用 BeautifulSoup 从网站上抓取数据
【发布时间】:2019-01-09 05:29:44
【问题描述】:

我无法从该网站抓取数据 http://hyd-app.rid.go.th/hydro5d.html

我使用 Beautiful Soup 来抓取数据。但是在导出文件中找不到数据inside table in the website

import requests
url = "http://hyd-app.rid.go.th/hydro5d.html"
data = requests.get(url)
time.sleep(20) 
print(data.status_code)
print(data.text)

如何将网站上的所有数据(包括表格数据)抓取到文本或 csv 文件中。

【问题讨论】:

    标签: python-3.x web-scraping


    【解决方案1】:

    @joke mamub 这是最终代码。它可以工作。测试它。

     import requests
     import pandas as pd
     from pandas.io.json import json_normalize
     import json
     headers = {
     'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, 
     like Gecko) Chrome/69.0.3497.81 Safari/537.36',
     'Referer': 'http://hyd-app.rid.go.th/hydro5d.html',
    }
    
    params = (
     ('option', '2'),
      )
    
     data = {
    'DW[UtokID]': '5',
    'DW[TimeCurrent]': '12/01/2562',
    '_search': 'false',
    'nd': '1547209026513',
    'rows': '1000',
    'page': '1',
    'sidx': 'indexcount',
    'sord': 'asc'
    }
    
    url = 'http://hyd- 
     app.rid.go.th/webservice/getDailyWaterLevelListReport5.ashx'
    
      response = requests.post(url, headers=headers, params=params, data=data)
      print(response.json())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-03
      • 2015-05-09
      相关资源
      最近更新 更多