Ok, so I've got some code I can't get to work. I'm trying to pull the first 10 urls from google for any given search result. I cannot get the results to print to the file, have had errors such as:
AtributeError: 'NoneType' object has no attribute
from bs4 import BeautifulSoup
import requests
import re
import urllib2
import os
jobid='test_01'
town='town'
KEIF="/home/dream/scripts/Keif/"
f = open(KEIF+'wordlists/trades.txt')
job = f.readline()
DIR="/home/dream/scripts/Keif/output/"+jobid
if not os.path.exists(DIR):
os.mkdir(DIR)
while job:
#Create google query
jobquery=job.replace(" ", "%20"); jobquery=jobquery.replace("/n ", "")
query = jobquery+'%20'+'in%20'+town
query= query.split()
query='+'.join(query)
#Create new text file based on query
jobdir=job.replace(" ","_"); jobdir=jobdir.replace("\n", "")
textpath=DIR+"/"+jobdir+'.txt'
os.system("cat "+textpath)
textOut=open(textpath, "a")
#Get Results
page = requests.get("https://www.google.co.uk/search?q="+query+"&start=10&num=10")
soup = BeautifulSoup(page.text, "html.parser")
print soup.find('cite').text
I am getting the:
AtributeError: 'NoneType' object has no atribute
on the last line print sou.find('cite').text
.
Can someone please help keep me from tearing out my hair!