在动态网页中获取特定关键字作为答案[关闭]

问题描述 投票:0回答:1

数据集:https://raw.githubusercontent.com/the-curious-analyst/Sem2NITDSProject/main/tanker-water-data-2015.csv

该数据集有一列名为“公寓所在区域”,我想搜索该区域中的每个项目+网站中的关键字“bengaluru”https://streets.openalfa.in/。在每次搜索的结果中,我希望区域名称作为输出(如果出现多个结果,我想要第一个结果的区域,如果没有结果为“N/A”)。搜索后,我想将所有输出合并到一个单列区域(对应于每个区域)。我无法使用 Selenium WebDriver。请原谅问题中含糊不清的任何错误。

def create_website_link(bareas):
  base_url = 'https://streets.openalfa.in/streets?q='
  links = []
  for bairro in bareas:
    if ' ' in bairro:
      bairro = bairro.replace(' ', '+')
    links.append(base_url + bairro)
  return links

bareas is a list containing all unique values in the specified areas column. 
I'm not able to retrieve the specific zone value of the first appearing result, since it's class changes with each result.

我是网络抓取的初学者,这就是我能想到的。

python selenium-webdriver web-scraping
1个回答
0
投票

填充链接列表后,您可以使用 BeautifulSoup 库以各种方式解析 HTML,包括查找第 n 个子元素。这应该允许您找到父元素内的第一个元素,该元素保存每次搜索的所有结果。

© www.soinside.com 2019 - 2024. All rights reserved.