我正在修改play-scraper API,以抓取Play商店应用的详细信息。它使用BeautifulSoup
来解析HTML页面[reference]。
我对一个应用程序可用的所有其他信息特别感兴趣,如下面的屏幕快照所示。 (以上屏幕截图来自此app。)
我坚持要提取应用程序要求的权限列表(如上图所示),因为View details
下的Permissions
URL如下。
<a class="hrTbp" jsname="Hly47e">View details</a>
单击View details
URL将显示我要提取的权限列表(如下所示的屏幕截图)。
我不熟悉Javascript。任何帮助将不胜感激。
答案 0 :(得分:2)
如果我正确理解了这个问题,则您正在尝试从模式中抓取数据。当网站首次加载时,这些模态数据在html中不可用。单击视图详细信息按钮后,将提取它们。这就是为什么解析器无法获取模态内部的数据的原因,在您的情况下是权限信息。因此,这就是您遇到问题的原因。
关于解决方案,现在可以使用Selenium和chromedriver来实现一种可能的解决方案,方法是对视图详细信息文本执行click事件,然后获取模态数据。看看this link有个好主意。
更新:要了解使用Selenium和chromedriver的解决方案,请考虑以下代码:
options = Options()
options.headless = True
driver = webdriver.Chrome('local_path_to_chrome_driver', options=options)
driver.get(url_of_the_play_store_app)
time.sleep(5) #sleep for 5 secs sometime to fetch the data
driver.find_element_by_link_text("View details").click() #performing the click event
time.sleep(5) # again sleep for 5 secs to fetch the modal data
soup = BeautifulSoup(driver.page_source, "lxml")
汤变量现在具有更新的抓取数据,包括模态窗口数据,您可以从汤中检索模态窗口数据。