Python 用漂亮的汤刮除超过渲染的数据

Python 用漂亮的汤刮除超过渲染的数据,python,selenium,beautifulsoup,Python,Selenium,Beautifulsoup,我从Google Play Store中抓取应用程序名称,对于每个URL输入,我只得到60个应用程序(因为如果用户不向下滚动,该网站会呈现60个应用程序)。它是如何工作的?我如何使用BeautifulSoup和/或Selenium从一个页面中刮取所有应用程序 多谢各位 这是我的密码: urls = [] urls.extend(["https://play.google.com/store/apps/category/NEWS_AND_MAGAZINES/collection/topselli

我从Google Play Store中抓取应用程序名称,对于每个URL输入,我只得到60个应用程序(因为如果用户不向下滚动,该网站会呈现60个应用程序)。它是如何工作的?我如何使用BeautifulSoup和/或Selenium从一个页面中刮取所有应用程序

多谢各位

这是我的密码:

urls = []

urls.extend(["https://play.google.com/store/apps/category/NEWS_AND_MAGAZINES/collection/topselling_paid"])

for i in urls:
    response = get(i)
    html_soup = BeautifulSoup(response.text, 'html.parser')
    app_container = html_soup.find_all('div', class_="card no-rationale square-cover apps small")
    file = open("./InputFiles/applications.txt","w+")
    for i in range(0, len(app_container)):
        #print(app_container[i].div['data-docid'])
        file.write(app_container[i].div['data-docid'] + "\n")

    file.close()
num_lines = sum(1 for line in open('./InputFiles/applications.txt'))
print("Applications : " + str(num_lines) )

在这种情况下,您需要使用
Selenium
。我为你尝试一下,并获得所有应用程序。我会尽力解释,希望你能理解

使用
Selenium
比其他Python函数更强大。我使用了ChromeDriver,所以如果您还没有安装,您可以在中安装它

输出:

1. Pocket Casts
Podcast Media LLC
₺24,99
2. Broadcastify Police Scanner Pro
RadioReference.com LLC
₺18,99
3. Relay for reddit (Pro)
DBrady
₺8,00
4. Sync for reddit (Pro)
Red Apps LTD
₺15,00
5. reddit is fun golden platinum (unofficial)
TalkLittle
₺9,99
... **UP TO 75**
注:

不要介意钱。这是我的国家货币,所以它会换成你的

更新您的评论:

1. Pocket Casts
Podcast Media LLC
₺24,99
2. Broadcastify Police Scanner Pro
RadioReference.com LLC
₺18,99
3. Relay for reddit (Pro)
DBrady
₺8,00
4. Sync for reddit (Pro)
Red Apps LTD
₺15,00
5. reddit is fun golden platinum (unofficial)
TalkLittle
₺9,99
... **UP TO 75**
span标记中也有相同的数据docid。您可以使用
get\u属性
获取它。只需将以下代码添加到您的项目中

y = driver.find_elements_by_css_selector("span[class=preview-overlay-container]")

for b in y :
   print b.get_attribute('data-docid')
输出

au.com.shiftyjelly.pocketcasts
com.radioreference.broadcastifyPro
reddit.news
com.laurencedawson.reddit_sync.pro
com.andrewshu.android.redditdonation
com.finazzi.distquakenoads
com.twitpane.premium
org.fivefilters.kindleit
.... UP TO 75

如果+60应用程序是用JS呈现的,那么您需要一些东西来呈现JS。请求不会完成它的超级任务,那不是真的……你可以在滚动时找出从JS发送的XHR,然后从请求发送这些XHR。这不是小事,但肯定是可行的。很酷,谢谢你,最后一个问题,我如何才能获得数据docid=“com.codified.hipyard”属性,而不是所有的div或应用程序名称?我在最后一部分回答了你的问题。你可以检查它@userHG享受你的编码:)@userHG