Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 浏览网页,在搜索栏中键入文本,然后搜索。。。但是当我点击搜索按钮时,文本消失了_Excel_Vba_Screen Scraping - Fatal编程技术网

Excel 浏览网页,在搜索栏中键入文本,然后搜索。。。但是当我点击搜索按钮时,文本消失了

Excel 浏览网页,在搜索栏中键入文本,然后搜索。。。但是当我点击搜索按钮时,文本消失了,excel,vba,screen-scraping,Excel,Vba,Screen Scraping,第一个帖子在这里。试图寻找类似的帖子,但没有找到任何东西 我对VBA有点陌生。我正在尝试使用Excel导航到特定网站,单击单选按钮,键入一些文本作为搜索字符串,然后搜索该文本。当我浏览我的代码时,一切看起来都很好,但是当我单击搜索按钮时,我的搜索字符串变为空白,并收到一条错误消息,告诉我输入搜索条件。代码如下: Sub FranklinCountyWebsite() 'References: Microsoft Internet Controls, Microsoft HTML Object L

第一个帖子在这里。试图寻找类似的帖子,但没有找到任何东西

我对VBA有点陌生。我正在尝试使用Excel导航到特定网站,单击单选按钮,键入一些文本作为搜索字符串,然后搜索该文本。当我浏览我的代码时,一切看起来都很好,但是当我单击搜索按钮时,我的搜索字符串变为空白,并收到一条错误消息,告诉我输入搜索条件。代码如下:

Sub FranklinCountyWebsite()
'References: Microsoft Internet Controls, Microsoft HTML Object Library

Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument

IE.Visible = True
IE.navigate "https://sheriff.franklincountyohio.gov/real-estate/"

Do While IE.readyState <> READYSTATE_COMPLETE
Loop

Set HTMLDoc = IE.document

HTMLDoc.getElementById("ctl00_SheetContentPlaceHolder_c_search1_rblSrchOptions_3").Click
HTMLDoc.getElementById("ctl00_SheetContentPlaceHolder_c_search1_SrchSearchString").Value = "43215"
HTMLDoc.getElementById("ctl00_SheetContentPlaceHolder_c_search1_btnSearch").Click

End Sub
Sub-FranklinCountyWebsite()
'参考:Microsoft Internet控件、Microsoft HTML对象库
Dim IE作为新的SHDocVw.InternetExplorer
将HTMLDoc设置为MSHTML.HTMLDocument
可见=真实
即“导航”https://sheriff.franklincountyohio.gov/real-estate/"
在IE.readyState readyState\u完成时执行此操作
环
设置HTMLDoc=IE.document
HTMLDoc.getElementById(“ctl00\u SheetContentPlaceHolder\u c\u search1\u rblSrchOptions\u 3”)。单击
HTMLDoc.getElementById(“ctl00\u SheetContentPlaceHolder\u c\u search1\u SrchSearchString”)。Value=“43215”
HTMLDoc.getElementById(“ctl00\u SheetContentPlaceHolder\u c\u search1\u btnSearch”)。单击
端接头

有趣的是,如果我去富兰克林县的网站,手动输入文本,然后点击搜索,一切正常。有什么容易忽略的吗?

您可以使用比IE快得多的
serverxmlhttp
请求来尝试同样的方法。下面的脚本可以引导您到达希望从中获取数据的目标页面

Sub Fetch_Item()
    Dim post As Object, qsp$, S$

    qsp = "q=searchType%3dZipCode%26searchString%3d43215%26foreclosureType%3d%26sortType%3daddress%26saleDateFrom%3d4%2f30%2f2017+12%3a00%3a00+AM%26saleDateTo%3d10%2f30%2f2018+11%3a59%3a59+PM"

    With New ServerXMLHTTP
        .Open "GET", "https://sheriff.franklincountyohio.gov/real-estate/results.aspx?" & qsp, False
        .setRequestHeader "User-Agent", "Mozilla/5.0"
        .send
        S = .responseText
    End With

    With New HTMLDocument
        .body.innerHTML = S
        Set post = .getElementById("ctl00_SheetContentPlaceHolder_C_searchresults_reSaleSummary_ctl00_lblAddrHeader")
        MsgBox post.innerText
    End With
End Sub
输出:

 155-157 CLEVELAND AVE COLUMBUS, OH 43215 010054688, 010055721
要添加到库中的引用:

Microsoft XML, V6.0
Microsoft HTML Object Library

它可以帮助在点击控件之前设置控件的焦点。让它工作起来——非常感谢。在我将搜索字符串设置为特定值的部分之前,我添加了“HTMLDoc.getElementById(“ctl00_SheetContentPlaceHolder_c_search1_SrchSearchString”).Focus”。好的,很酷,很好。嘿@SIM,我很感激。当我在一周前问这个问题时,我只是想让一切都与IE一起工作,并对使用VBA进行web抓取有一个粗略的了解,但我昨天看到了你的评论,并开始考虑使用XML库来加快速度。谢谢像往常一样回答得很好