python - 用 selenium 和 python 抓取
问题描述
我试图将我的脚趾浸入硒的世界,但我在理解事物的工作原理时遇到了问题。
首先我只是想学习抓取网站。
以这个网站为例
我希望能够抓取所有可用的优惠券并返回:标题、日期、网址链接。
现在我可以在 BeautifulSoup 中使用
search_coupon = soup.find_all('div',{'class':'td_module_1 td_module_wrap td-animation-stack'})
for coupon in search_coupon:
coupon_title = coupon.find('h3',{'class':'entry-title td-module-title'}).text
coupon_date = coupon.find('span',{'class':'td-post-date'}).text
coupon_url = coupon.find('a').get('href')
print(coupon_title, coupon_date, coupon_url)
我如何用硒做到这一点?
我似乎无法以相同的方式检索对象
帮助 !!:)
解决方案
你可以从:
# Definning some basic functions for later usage
def clickOnId(id):
browser.find_element_by_id(id).click()
def clickOnXpath(xpath):
browser.find_element_by_xpath(xpath).click()
def clickOnClass(class_name):
browser.find_element_by_class_name(class_name).click()
def TypeInId(id,toBeTyped):
elems = browser.find_elements_by_id(id)
elems[0].send_keys(toBeTyped)
def TypeInXpath(xpath,toBeTyped):
elems = browser.find_elements_by_xpath(xpath)
elems[0].send_keys(toBeTyped)
并查看此代码以进入 selenium。
推荐阅读
- python - 如何使用熊猫按字母顺序将数据分类?
- c# - 使用 C# Oracle 托管数据 nuget 和存储过程的 Arraybinding 示例
- javascript - 如何在排序的数字列表中合并连续的数字?
- python - 当参数恒定时,是否适合在 python 类中使用闭包?
- python - 在 Scala Spark 和 PySpark 之间传递多个 DataFrame
- javascript - 当应用程序在后台时,如何让服务人员处理推送?
- pyspark - 在 pyspark 数据框中查找连续数据
- reactjs - 在 Android 上强制退出并重新打开应用程序后,组件上的引用为空
- xml - 使用正确的 xpath 捕获值
- c - 为什么将 double 转换为 int 可能会产生不同的结果?