我可以清楚地看到我需要的标签,以便获取我想要抓取的数据。
根据多个教程,我的做法完全相同。
那么,当我只想在 li
类之间显示代码时,为什么它给我“无”
from bs4 import BeautifulSoup
import requests
response = requests.get("https://www.governmentjobs.com/careers/sdcounty")
soup = BeautifulSoup(response.text,'html.parser')
job = soup.find('li', attrs = {'class':'list-item'})
print(job)
最佳答案
虽然页面会动态更新(它会从浏览器发出额外的请求来更新您没有通过单个请求捕获的内容),但您可以在网络选项卡中找到感兴趣内容的源 URI。您还需要添加预期的 header 。
import requests
from bs4 import BeautifulSoup as bs
headers = {'X-Requested-With': 'XMLHttpRequest'}
r = requests.get('https://www.governmentjobs.com/careers/home/index?agency=sdcounty&sort=PositionTitle&isDescendingSort=false&_=', headers=headers)
soup = bs(r.content, 'lxml')
print(len(soup.select('.list-item')))
关于python - 使用 beautifulsoup 解析 HTML 给出 "None",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58783950/