从网站上抓取多个列表。
Scraping multiple lists from a website.
我目前正在为显示 table 数据的网站开发网络抓取工具。我 运行 遇到的问题是网站在第一次搜索时没有按州对我的搜索进行排序。我必须在加载时通过第二页上的下拉菜单执行此操作。我加载第一页的方式是我认为是 WebClient POST 请求。我得到了正确的 html 响应并且可以解析它,但我想加载过滤更多的搜索,但是当我将它与 html I 进行比较时,我返回的 html 是不正确的在 chrome 开发人员选项卡中查看。
这是我的代码
// The website I'm looking at.
public string url = "https://www.missingmoney.com/Main/Search.cfm";
// The POST requests for the working search, but doesn't filter by states
public string myPara1 = "hJava=Y&SearchFirstName=Jacob&SearchLastName=Smith&HomeState=MN&frontpage=1&GO.x=19&GO.y=18&GO=Go";
// The POST request that also filters by state, but doesn't return the correct html that I would need to parse
public string myPara2 = "hJava=Y&SearchLocation=1&SearchFirstName=Jacob&SearchMiddleName=&SearchLastName=Smith&SearchCity=&SearchStateID=MN&GO.x=17&GO.y=14&GO=Go";
// I save the two html responses in these
public string htmlResult1;
public string htmlResult2;
public void LoadHtml(string firstName, string lastName)
{
using (WebClient client = new WebClient())
{
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
htmlResult1 = client.UploadString(url, myPara1);
htmlResult2 = client.UploadString(url, myPara2);
}
}
只是想弄清楚为什么我第一次传入参数时有效,而在第二次传入参数时却无效。
感谢您花时间看这篇文章!!!
我只是忘了将 cookie 添加到新搜索中。使用 google chrome 或 fiddler 你可以看到网络流量。我需要做的就是添加
client.Headers.Add(HttpRequestHeader.Cookie, "cookie");
在我的代码上传之前。这样做给了我正确的 html 响应,我现在可以解析我的数据。
@derloopkat 指出了这一点,归功于那个人!!!
我目前正在为显示 table 数据的网站开发网络抓取工具。我 运行 遇到的问题是网站在第一次搜索时没有按州对我的搜索进行排序。我必须在加载时通过第二页上的下拉菜单执行此操作。我加载第一页的方式是我认为是 WebClient POST 请求。我得到了正确的 html 响应并且可以解析它,但我想加载过滤更多的搜索,但是当我将它与 html I 进行比较时,我返回的 html 是不正确的在 chrome 开发人员选项卡中查看。
这是我的代码
// The website I'm looking at.
public string url = "https://www.missingmoney.com/Main/Search.cfm";
// The POST requests for the working search, but doesn't filter by states
public string myPara1 = "hJava=Y&SearchFirstName=Jacob&SearchLastName=Smith&HomeState=MN&frontpage=1&GO.x=19&GO.y=18&GO=Go";
// The POST request that also filters by state, but doesn't return the correct html that I would need to parse
public string myPara2 = "hJava=Y&SearchLocation=1&SearchFirstName=Jacob&SearchMiddleName=&SearchLastName=Smith&SearchCity=&SearchStateID=MN&GO.x=17&GO.y=14&GO=Go";
// I save the two html responses in these
public string htmlResult1;
public string htmlResult2;
public void LoadHtml(string firstName, string lastName)
{
using (WebClient client = new WebClient())
{
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
htmlResult1 = client.UploadString(url, myPara1);
htmlResult2 = client.UploadString(url, myPara2);
}
}
只是想弄清楚为什么我第一次传入参数时有效,而在第二次传入参数时却无效。
感谢您花时间看这篇文章!!!
我只是忘了将 cookie 添加到新搜索中。使用 google chrome 或 fiddler 你可以看到网络流量。我需要做的就是添加
client.Headers.Add(HttpRequestHeader.Cookie, "cookie");
在我的代码上传之前。这样做给了我正确的 html 响应,我现在可以解析我的数据。
@derloopkat 指出了这一点,归功于那个人!!!