BeautifulSoup Scraping错误:AttributeError:'NoneType'对象没有属性 [英] BeautifulSoup Scraping ERROR: AttributeError: 'NoneType' object has no attribute

查看:59
本文介绍了BeautifulSoup Scraping错误:AttributeError:'NoneType'对象没有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个倒计时求解器程序,以从站点中抓取解决方案.

I am trying to make a countdown solver program to scrape solutions from a site.

我该如何刮擦文本的最后一行?

How can I scrape the last line of this text?

我尝试过:

numbers = [23,43,65,43,7,3]
target = 200

r = requests.get("http://rve.org.uk/countdown?n="+str(numbers[0])+"&n="+str(numbers[1])+"&n="+str(numbers[2])+"&n="+str(numbers[3])+"&n="+str(numbers[4])+"&n="+str(numbers[5])+"&t="+str(target))

soup = BeautifulSoup(r.content)
print(soup.find('pre').text)

AttributeError:'NoneType'对象没有属性'text'

AttributeError: 'NoneType' object has no attribute 'text'

推荐答案

尝试一下:

import requests
from bs4 import BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
          'Upgrade-Insecure-Requests': '1', 'Cookie': 'v2=1495343816.182.19.234.142', 'Accept-Encoding': 'gzip, deflate, sdch',
           'Referer': 'http://rve.org.uk/countdown', 'Host': 'rve.org.uk'}
r = requests.get('http://rve.org.uk/countdown?n=65&n=43&n=43&n=23&n=7&n=3&t=200',headers=headers)
soup = BeautifulSoup(r.content,'html.parser')
print(soup.find('pre').text)

它将为您服务:

65 = 65
65 + 43 + 23 + 7 + 3 = 141
65 + 43 + 43 + 23 + 7 + 3 = 184
43 * (43 + 23 + 7 - 65 - 3) = 215
(43 + 23) * (7 - 3) - 65 = 199
65 + (23 - 7) * 3 + 43 + 43 = 199
23 * (7 - 43 / 43) + 65 - 3 = 200
(43 + 7) * (43 + 23 + 3 - 65) = 200
(43 + 7) * (23 * 3 - 65) = 200
23 * (7 - 3) + 65 + 43 = 200
(43 + 43) * 3 + 7 - 65 = 200
(65 + 23 - 7) * 3 - 43 = 200
(65 - 43) * 7 + 43 + 3 = 200
(65 * 3 - 23) * (43 + 7) / 43 = 200
(65 - 43) * (7 + 3) + 23 - 43 = 200
(65 + 43 + 7) * (43 - 3) / 23 = 200
(65 + 43 / 43 - 7) * 3 + 23 = 200
65 * (43 - 3) / (43 - 23 - 7) = 200
(43 - 23) * (7 + 3) = 200

这篇关于BeautifulSoup Scraping错误:AttributeError:'NoneType'对象没有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆