试图从parsehub api获取数据到vb.net

时间:2016-04-03 11:09:59

标签: json vb.net api parsehub

我正在尝试使用parsehub api(https://www.parsehub.com/docs/ref/api/v2/?python#get-a-project)从网上导入json到我的vb.net来抓取数据

我对vb.net非常熟悉,但文档部分给出的所有示例都是curl,python,ruby或php。

curl中的api代码是:

curl "https://www.parsehub.com/api/v2/projects/{PROJECT_TOKEN}/run"   -X POST \ 
  -d api_key=tElpQTK_W2mrPKYPl1gug0RE \ 
  -d start_url=http%3A%2F%2Fwww.example.com \ 
  -d start_template=main_template \ 
  -d start_value_override=%7B%22query%22%3A+%22San+Francisco%22%7D \ 
  -d send_email=1
{
  "project_token": "t-0WMEZ-Bc9sWGHAMsYvP7y4", 
  "run_token": "tCcB4hfFP6wvBRe2gwZv9aJp", 
  "status": "initialized", 
  "data_ready": false, 
  "start_time": "2015-02-03T23:09:38", 
  "end_time": null, 
  "pages": 0, 
  "md5sum": null, 
  "start_url": "http://www.example.com", 
  "start_template": "main_template", 
  "start_value": "{\"query\": \"San Francisco\"}"
}

我到目前为止尝试在vb.net中执行此操作

    Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click


  dgv2.Rows.Clear()
            Dim uri As Uri = New Uri("https://www.parsehub.com/api/v2/projects/{PROJECT_TOKEN}/run")
            Dim wc1 As System.Net.WebClient = New System.Net.WebClient()
            Dim VCItem As String = wc1.DownloadString(uri)
            Dim o As JObject = JObject.Parse(VCItem)
            Dim results As List(Of JToken) = o.Children().ToList


            'Try
            For Each item As JProperty In results
                    item.CreateReader()
                    If item.Value.Type = JTokenType.Array Then
                        For Each subitem As JObject In item.Values



                        dgv2.Rows.Add(subitem("leftlabelcells_value"), (subitem("hideextra_number")), (subitem("rightpositioncells_number")))


                    Next
                    End If

但我得到一个禁止的错误,它不起作用。 任何帮助将非常感激,并坚持使用此代码多年,我不知道该怎么做。

谢谢。

1 个答案:

答案 0 :(得分:0)

您希望将调用中的{PROJECT_TOKEN}替换为项目中的实际令牌,您可以在编辑项目时在设置选项卡下找到该令牌。

希望有所帮助。将来,您可以随时通过parsehub dot com的支持向我们发送电子邮件,以便您获得更快的响应。