Python BeautifulSoup刮片错误:AttributeError:&x27;非类型';对象没有属性

Python BeautifulSoup刮片错误:AttributeError:&x27;非类型';对象没有属性,python,html,parsing,web-scraping,beautifulsoup,Python,Html,Parsing,Web Scraping,Beautifulsoup,我正试图做一个倒计时求解程序,从一个网站刮解决方案 我怎样才能把这篇课文的最后一行删掉 我试过这个: 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="+st

我正试图做一个倒计时求解程序,从一个网站刮解决方案

我怎样才能把这篇课文的最后一行删掉

我试过这个:

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:“非类型”对象没有属性“文本”


下面是打印状态代码和原因的示例。还要注意,我使用了一个解析器来指定我们正在解析HTML

import requests
from bs4 import BeautifulSoup

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.text, "html.parser")

print("The status code of the response: %d, the reason is: %s, the text returned is: %s " % 
     (r.status_code, r.reason, r.text))
输出:

The status code of the response: 403, the reason is: Forbidden, the text returned is:
试试这个:

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

如果你有错误,告诉我们,不要只告诉我们“我有错误”。我会胡乱猜测,你的括号放错地方了
soup.find(“pre”).text
而不是
soup.find(“pre.text”)
。抱歉。我得到了非类型AttributeError。正如@JohnGordon提到的,使用
打印(soup.find('pre').text)
@Tiny.D。它不起作用(是的,这是禁止的。有没有其他方法可以废弃内容?你是如何获得你在问题中发布的示例HTML的?我猜正确的URL是:
http://rve.org.uk/countdown?n=10&n=10&n=10&n=10&n=10&n=1&t=11
?@JohnGordon来自rve.org.uk,现在它可以工作了。我想这只是一个请求问题。它们可以防止“不安全的请求”很抱歉,这一个将从我的本地pc获取cookie。不是从网站获取cookie。我将在@tiny更改cookie