如何解析HTML Google搜索结果?
< 20%EC%A0%84%EC%A3%BC%EB%8C%8C%EC%A0%90%20%EC%A0%A0%84%EB%B6%81%20%EC%A0%A0%A0%84%EC% A3%BC%EC%8B%9C%20%EC%99%84%EC%82%B0%EA%B5%AC%AC%20%EC%B2%B2%9C%EC%9E%A0%A0%A0%A0%EB%A1%9C% 20303%20%EB%84%A4%EC%9D%B4%EB%B2%84MyPlace“ rel =” nofollow noreferrer“> https://www.google.com/search?q=%EB%8D%94%; ED%81%B0%EB%8F%84%EC%8b%9C%EB%9D%BD%20%EC%A0%A0%EC%A3%A3%BC%EB%EB%8C%8C%80%EC%EC%A0%90% 20%EC%A0%84%EB%B6%81%20%EC%A0%84%EC%A3%BC%EC%8b%9C%20%EC%99%84%EC%EC%82%B0%EA EA B5%AC%20%EC%B2%9C%EC%9E%A0%EB%A1%9C%20303%20%EB%84%A4%EC%9D%B4%B4%EB%B2%B2%84MyPlace
IS我想解析的结果。
问题是...我无法解析搜索结果的第一行。
以下是我在代码中进行的方式。
final naverUserAgentHeader = {
HttpHeaders.userAgentHeader:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'
};
final response = await http.get(uri, headers: naverUserAgentHeader);
Document document = parser.parse(response.body);
List<Element> classList = document.getElementsByClassName("jGGQ5e");
for (int i = 0; i < classList.length; i++) {
if(classList[i]
.getElementsByTagName("div").length!=0){
var aaa = classList[i]
.getElementsByTagName("div")[0].text;
print("aaa...!");
print(aaa);
}
}
is the result that I want to parse.
the problem is...I can't parse first row of search result.
below is how I did it in code.
final naverUserAgentHeader = {
HttpHeaders.userAgentHeader:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'
};
final response = await http.get(uri, headers: naverUserAgentHeader);
Document document = parser.parse(response.body);
List<Element> classList = document.getElementsByClassName("jGGQ5e");
for (int i = 0; i < classList.length; i++) {
if(classList[i]
.getElementsByTagName("div").length!=0){
var aaa = classList[i]
.getElementsByTagName("div")[0].text;
print("aaa...!");
print(aaa);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论