Skip to content Skip to sidebar Skip to footer

Beautifulsoup Scraping Error: Attributeerror: 'nonetype' Object Has No Attribute

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? I tried this: numbers = [23,43,65,43,7,3] target = 20

Solution 1:

Try this:

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)

It will work for you:

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

Solution 2:

Here's your example with the status code and reason printed. Also note that I've used a parser to specify that we are parsing 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 output:

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

Post a Comment for "Beautifulsoup Scraping Error: Attributeerror: 'nonetype' Object Has No Attribute"