【问题标题】:Scraper not extracting url link:Scraper 未提取 url 链接:
【发布时间】:2019-07-08 01:38:26
【问题描述】:

您好,我正在尝试抓取链接在“在亚马逊上查看商品”下的本网站上的亚马逊 url 地址。

我的代码在下面,我得到零响应。感谢任何帮助。谢谢

import requests
url = "https://app.jumpsend.com/deals/230513"

response = requests.get(url)
data = response.text

soup = BeautifulSoup(data, 'lxml')

tags = soup.find_all('a')

for tag in tags:
    print(tag.get('href'))

【问题讨论】:

  • 打印data你会看到的。

标签: python beautifulsoup screen-scraping


【解决方案1】:

亚马逊链接 (https://www.amazon.com/dp/B07MH9DK5B) 不在 html 页面源中。您需要使用 Selenium 来读取 Java 脚本设置的所有元素的 html:

from bs4 import BeautifulSoup
from selenium import webdriver

url = "https://app.jumpsend.com/deals/230513"
driver = webdriver.Firefox()
driver.get(url)
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
soup.find('a', attrs={'class': 'deal-modal-link'})['href']

以上代码打印出亚马逊链接:

'https://www.amazon.com/dp/B07MH9DK5B'

【讨论】:

    猜你喜欢
    • 2020-10-04
    • 1970-01-01
    • 2015-02-26
    • 1970-01-01
    • 2021-01-26
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    • 2023-03-28
    相关资源
    最近更新 更多