【问题标题】:I wish to scrape a site with buttons, drop down list and search我希望用按钮、下拉列表和搜索来抓取网站
【发布时间】:2020-07-03 16:09:13
【问题描述】:

''' 我有一个网页代码,但在不同的链接上。但是由于下拉选项卡,我无法抓取这个。有没有一种通用的方法来抓取具有这种结构的网页,还是我们必须查看结构并抓取? 这是我要抓取的链接:https://www.moneycontrol.com/markets/fno-market-snapshot

from bs4 import BeautifulSoup
import requests
import pandas as pd
import time
r=requests.get('https://www.moneycontrol.com/india/stockpricequote/')

#We want to view the data in text format
data=r.text

#we can check some part of this html data
print(data[:1000])

soup=BeautifulSoup(data,'html.parser')

mydivs = soup.findAll("a", {"class": "bl_12"})
values=[]
for link in mydivs:
    value=link.get('href')
    values.append(value)


values= [ link.get('href') for link in mydivs]
values[0:5]
#create a temp Df
pd.set_option('max_colwidth', 800)
stock_data = pd.DataFrame({'LINK': values})

print(stock_data.shape)
stock_data.head(5)

【问题讨论】:

    标签: javascript html python-3.x web-scraping


    【解决方案1】:

    不,不是。网络爬虫和爬虫可以点击页面中可用的链接排列或抓取数据,但是当您有复杂的 UI 进行额外调用时,确实没有一般的方法可以轻松地做到这一点。如果他们允许,您将需要遍历 UI 以抓取或挂钩到他们的 API。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-19
    • 2021-06-27
    相关资源
    最近更新 更多