Python 查找带有';变量';?但是没有类-漂亮的汤/蟒蛇

Python 查找带有';变量';?但是没有类-漂亮的汤/蟒蛇,python,beautifulsoup,Python,Beautifulsoup,我正在使用BeautifulSoup和Python查找一个似乎没有类的span标记 我想在span标签中得到文本“1小时前”,它有一个。。。变量被称为“数据自动化”,但我似乎无法找到如何使用漂亮的汤找到它 第一个跨度有一个类“\u 3mgsa7-\u 2CsjSEq\u 2gpxOIH\u 15GBVuT\u 3VdCwhL\u 2Ryjovs”,它使用我的代码生成文本,但也有一个错误 有人能帮我修复错误或解释如何找到“数据自动化”span标记吗 我的代码: joblist =soup.find

我正在使用BeautifulSoup和Python查找一个似乎没有类的span标记

我想在span标签中得到文本“1小时前”,它有一个。。。变量被称为“数据自动化”,但我似乎无法找到如何使用漂亮的汤找到它

第一个跨度有一个类“
\u 3mgsa7-\u 2CsjSEq\u 2gpxOIH\u 15GBVuT\u 3VdCwhL\u 2Ryjovs
”,它使用我的代码生成文本,但也有一个错误

有人能帮我修复错误或解释如何找到“数据自动化”span标记吗

我的代码:

joblist =soup.find_all('article', class_='_37iADb_ _3BsYYYt')
for job in joblist:
    listed = job.find('span', class_="_3mgsa7- _2CsjSEq _2gpxOIH _15GBVuT _3VdCwhL _2Ryjovs").text
    print(f'listed {listed}')
  Traceback (most recent call last):
      File "C:\Users\User\PycharmProjects\Scraping1\ScrapeTut 2 - scraping websites.py", line 34, in <module>
        listed = job.find('span', class_="_3mgsa7- _2CsjSEq _2gpxOIH _15GBVuT _3VdCwhL _2Ryjovs").text
    AttributeError: 'NoneType' object has no attribute 'text'
<span class="_3mgsa7- _2CsjSEq _2gpxOIH _15GBVuT _3VdCwhL _2Ryjovs">
  <span class="">
    <span aria-hidden="true" data-automation="jobListingDate">1h ago</span>
  </span>
</span>
错误:

joblist =soup.find_all('article', class_='_37iADb_ _3BsYYYt')
for job in joblist:
    listed = job.find('span', class_="_3mgsa7- _2CsjSEq _2gpxOIH _15GBVuT _3VdCwhL _2Ryjovs").text
    print(f'listed {listed}')
  Traceback (most recent call last):
      File "C:\Users\User\PycharmProjects\Scraping1\ScrapeTut 2 - scraping websites.py", line 34, in <module>
        listed = job.find('span', class_="_3mgsa7- _2CsjSEq _2gpxOIH _15GBVuT _3VdCwhL _2Ryjovs").text
    AttributeError: 'NoneType' object has no attribute 'text'
<span class="_3mgsa7- _2CsjSEq _2gpxOIH _15GBVuT _3VdCwhL _2Ryjovs">
  <span class="">
    <span aria-hidden="true" data-automation="jobListingDate">1h ago</span>
  </span>
</span>
回溯(最近一次呼叫最后一次):
文件“C:\Users\User\PycharmProjects\Scraping1\scraptut 2-scraping websites.py”,第34行,在
列出=作业。查找('span',class=“\u 3mgsa7-\u 2CsjSEq\u 2gpxOIH\u 15GBVuT\u 3VdCwhL\u 2Ryjovs”)。文本
AttributeError:“非类型”对象没有属性“文本”
网站HTML代码:

joblist =soup.find_all('article', class_='_37iADb_ _3BsYYYt')
for job in joblist:
    listed = job.find('span', class_="_3mgsa7- _2CsjSEq _2gpxOIH _15GBVuT _3VdCwhL _2Ryjovs").text
    print(f'listed {listed}')
  Traceback (most recent call last):
      File "C:\Users\User\PycharmProjects\Scraping1\ScrapeTut 2 - scraping websites.py", line 34, in <module>
        listed = job.find('span', class_="_3mgsa7- _2CsjSEq _2gpxOIH _15GBVuT _3VdCwhL _2Ryjovs").text
    AttributeError: 'NoneType' object has no attribute 'text'
<span class="_3mgsa7- _2CsjSEq _2gpxOIH _15GBVuT _3VdCwhL _2Ryjovs">
  <span class="">
    <span aria-hidden="true" data-automation="jobListingDate">1h ago</span>
  </span>
</span>

1小时前
您可以通过将
attrs
dict作为关键字参数传递给
.find()
.find_all()
来选择具有特定属性的
元素(例如
数据自动化
)。看

要查找
,其中
数据自动化
具有任何值:

soup.find('span',attrs={'data-automation':True})
其中,
数据自动化
具有特定值:

soup.find('span',attrs={'data-automation':'jobListingDate'})

您可以包括您试图废弃的网站的url吗?请尝试使用
类型(作业)
类型(列出)
打印
作业的类型和
列出的类型