python - 有没有一种特殊的方法来抓取动态网站?

标签 python web-scraping beautifulsoup scrapy mechanize

我想抓取 the following webpage .

搜索框(上面写着输入安全名称/代码/ID)是我遇到困难的地方。我无法使用 xpath 抓取它,我正在使用 mechanize 库进行浏览器模拟,但它似乎不起作用。

我遇到了这个问题 Excel VBA Scrape Web Page这与我的问题非常相似,但我不知道如何使用 Python 来实现它。

我试过的代码:

import mechanize
from bs4 import BeautifulSoup
import requests
url = 'https://www.bseindia.com/corporates/corporate_act.aspx'
res = requests.get(url)
soup = BeautifulSoup(res.text, "html.parser")
br = mechanize.Browser()
br.open(url)
br.select_form(nr=0)
br['ContentPlaceHolder1_SmartSearch_smartSearch'] = input("enter the company name")
response = br.submit()

PS:我是网络抓取的新手,我想知道大学项目的解决方案,因此非常感谢您的帮助。

最佳答案

我建议你使用 scrapy框架。我认为它是更先进的工具之一,包括模拟与站点交互的工具。

关于python - 有没有一种特殊的方法来抓取动态网站?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60044303/

相关文章:

python - 使用 Python Beautifulsoup 抓取天使列表配置文件描述

go - Chromedp 包 : How to get updated HTML source of the webpage which has dynamically loaded contents by using chromedp

python - Beautifulsoup:当我尝试使用 Beautifulsoup4 访问 soup.head.next_sibling 值时换行

css - Web Scraping contents of::before::after CSS伪元素使用BeautifulSoup

python - NumPy 和 MATLAB 之间特征向量的微小差异

python - 我可以在单元测试的设置阶段编译 numba 吗?

web-scraping - 维基解密有一个不寻常的 robots.txt。我可以抓取什么?

python - Pandas:无法从 DataFrame 列中剥离 HTML 标签

python - 在 Pandas eval 中调用 round()、ceiling()、floor()、min()、max()

Python 3 urllib.request.urlopen