Max*_*Max 6 python selenium xpath css-selectors webdriverwait
抓取链接应该是一件简单的事情,通常只需获取srca 标签的值即可。
我最近发现这个网站(https://sunteccity.com.sg/promotions),其中每个项目的a标签的href值都找不到,但重定向仍然有效。我正在尝试找出一种方法来获取项目及其相应的链接。我典型的 python selenium 代码看起来像这样
all_items = bot.find_elements_by_class_name('thumb-img')
for promo in all_items:
a = promo.find_elements_by_tag_name("a")
print("a[0]: ", a[0].get_attribute("href"))
Run Code Online (Sandbox Code Playgroud)
但是,我似乎无法检索任何href,onclick属性,我想知道这是否可能。我注意到我也无法在新选项卡中右键单击打开链接。
有什么方法可以获取所有这些项目的链接吗?
编辑: 有什么方法可以检索页面上项目的所有链接吗?
IE
https://sunteccity.com.sg/promotions/724
https://sunteccity.com.sg/promotions/731
https://sunteccity.com.sg/promotions/751
https://sunteccity.com.sg/promotions/752
https://sunteccity.com.sg/promotions/754
https://sunteccity.com.sg/promotions/280
...
Run Code Online (Sandbox Code Playgroud)
通过对 Javascript 进行逆向工程,将您带到促销页面(参见https://sunteccity.com.sg/_nuxt/d4b648f.js),这为您提供了一种获取所有链接的方法,这些链接基于HappeningID. 您可以通过在 JS 控制台中运行它来验证,这会给您带来第一次提升:
window.__NUXT__.state.Promotion.promotions[0].HappeningID
Run Code Online (Sandbox Code Playgroud)
基于此,您可以创建一个 Python 循环来获取所有促销:
items = driver.execute_script("return window.__NUXT__.state.Promotion;")
for item in items["promotions"]:
base = "https://sunteccity.com.sg/promotions/"
happening_id = str(item["HappeningID"])
print(base + happening_id)
Run Code Online (Sandbox Code Playgroud)
这生成了以下输出:
https://sunteccity.com.sg/promotions/724
https://sunteccity.com.sg/promotions/731
https://sunteccity.com.sg/promotions/751
https://sunteccity.com.sg/promotions/752
https://sunteccity.com.sg/promotions/754
https://sunteccity.com.sg/promotions/280
https://sunteccity.com.sg/promotions/764
https://sunteccity.com.sg/promotions/766
https://sunteccity.com.sg/promotions/762
https://sunteccity.com.sg/promotions/767
https://sunteccity.com.sg/promotions/732
https://sunteccity.com.sg/promotions/733
https://sunteccity.com.sg/promotions/735
https://sunteccity.com.sg/promotions/736
https://sunteccity.com.sg/promotions/737
https://sunteccity.com.sg/promotions/738
https://sunteccity.com.sg/promotions/739
https://sunteccity.com.sg/promotions/740
https://sunteccity.com.sg/promotions/741
https://sunteccity.com.sg/promotions/742
https://sunteccity.com.sg/promotions/743
https://sunteccity.com.sg/promotions/744
https://sunteccity.com.sg/promotions/745
https://sunteccity.com.sg/promotions/746
https://sunteccity.com.sg/promotions/747
https://sunteccity.com.sg/promotions/748
https://sunteccity.com.sg/promotions/749
https://sunteccity.com.sg/promotions/750
https://sunteccity.com.sg/promotions/753
https://sunteccity.com.sg/promotions/755
https://sunteccity.com.sg/promotions/756
https://sunteccity.com.sg/promotions/757
https://sunteccity.com.sg/promotions/758
https://sunteccity.com.sg/promotions/759
https://sunteccity.com.sg/promotions/760
https://sunteccity.com.sg/promotions/761
https://sunteccity.com.sg/promotions/763
https://sunteccity.com.sg/promotions/765
https://sunteccity.com.sg/promotions/730
https://sunteccity.com.sg/promotions/734
https://sunteccity.com.sg/promotions/623
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
727 次 |
| 最近记录: |