【问题标题】:Cannot WebScrape text from image link无法从图像链接中抓取文本
【发布时间】:2021-11-14 14:30:14
【问题描述】:

我无法从亚马逊产品页面抓取评分百分比。我只得到空值。这是我的代码

from typing import Text
from bs4 import BeautifulSoup
import requests
import pandas as pd
from datetime import date
import os

url='https://www.amazon.in/dp/B09BJQCTMX?ref=myi_title_dp'
req = requests.get(url)
content=BeautifulSoup(req.content,"lxml")
data = content.findAll('a',class_='a-link-normal')
print(data)

我提供了正确的类名,但检索到的只有空值。

【问题讨论】:

  • 尝试打印req.text。它将打印整个 html 页面,在那个大字符串中,如果您需要的数据存在,那么您可以使用 bs4 访问特定数据。如果没有那么你需要使用其他方式

标签: python html web-scraping beautifulsoup alfresco-webscripts


【解决方案1】:

尝试将headers 放入请求调用中,数据将出现在content

headers={"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"}
url='https://www.amazon.in/dp/B09BJQCTMX?ref=myi_title_dp'
req = requests.get(url,headers=headers)
content=BeautifulSoup(req.content,"lxml")

现在使用适当的class 来查找数据

text_data=content.find("span",class_="a-list-item").get_text(strip=True)
href_data=content.find("span",class_="a-list-item").find("a")['href']

图片:

【讨论】:

  • 我们可以对 Flipkart 卖家门户网站进行 webscrap(登录后)吗?
  • 您可以这样做,但您必须通过凭据并且必须进行身份验证,因此请查找
  • 您能否提供资源链接,我可以在其中学习必要的概念。
猜你喜欢
  • 2021-10-12
  • 2021-05-11
  • 2016-12-14
  • 2021-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多