2016-04-04 16 views
0

Ben piton 2.7.8 kullanıyorum. Gerçekten ne olduğunu bilmiyorum. Her şey iyi gidiyordu ama aniden bu hata ortaya çıktı. Bunun ne olduğunu anlamıyorum. Çok ara ama çözmek için başarısız.piton 2.7.8IOError: [Errno 2] Sistem belirtilen yolu bulamıyor: '\ ayarları \ reklamlarının \ tercihlerini hl = tr'

tam Hata geçerli:

#!/usr/bin/env python 
import re 
import requests 

import urllib 
from bs4 import BeautifulSoup 

def addtoindex(self, url, soup): 
     if self.isindexed (url): return 
     print 'Indexing ' + url 
     # Get the individual words 
     text = self.getTtextonly(url) 
     #print 't',text 
     words = self.separatewords(text) 
     #print 'words',words 
     if stem: words = pracstem.stem(words) 
     # Get the URL id 
     urlid = self.getentryid('googleurllist', 'url', url) 
     #print 'id',urlid 
     # Link each word to this url 
     for i in range(len(words)): 
      word = words[i] 
      # print 'w',word 
      if word in ignorewords: continue 
      wordid = self.getentryid('googlewordlist', 'word', word) 
      #print 'wordid',wordid 

      self.con.execute("insert into googlewordlocation(urlid, wordid, location) values('{0}', '{1}', '{2}')" .format(urlid, wordid, i)) 
      self.con.commit() 


def getTtextonly(self, soup): 
     url = soup 
     #url = "http://www.cplusplus.com/doc/tutorial/program_structure/" 
     html = urllib.urlopen(url).read() # compiler pointing error here 
     soup = BeautifulSoup(html) 

     # kill all script and style elements 
     for script in soup(["script", "style","a","<div id=\"bottom\" >"]): 
      script.extract() # rip it out 

     text = soup.findAll(text=True) 
     return text 

def findfromGoogle(self,a): 

    page = requests.get("https://www.google.com/search?q="+a) 
    soup = BeautifulSoup(page.content) 
    links = soup.findAll("a") 
    for link in links: 
     if link['href'].startswith('/url?q=') \ 
     and 'webcache.googleusercontent.com' not in link['href']: 
      q = link['href'].split('/url?q=')[1].split('&')[0] 
      #self.con.execute("insert into wordlocation(urlid, wordid, location) values(%i, %i, %i)" %(urlid, wordid, i)) 
      # self.con.execute("insert into googleurllist (keyword,url,relevance,textcomplexity)VALUES('{0}','{1}','{2}','{3}')" .format(a,q,'','')) 
      # linkText = self.gettextonly(q) 
      #self.con.commit() 
      print "Records created successfully"; 
      print q 
      self.addtoindex(q,soup) 
      linkText = self.getTtextonly(q) 

Hata:

File "C:\Users\DELL\Desktop\python\s\fyp\Relevancy\M\pyThinSearch\test.py", in getTtextonly 
    html = urllib.urlopen(url).read() 
    File "C:\Python27\lib\urllib.py", line 87, in urlopen 
    return opener.open(url) 
    File "C:\Python27\lib\urllib.py", line 208, in open 
    return getattr(self, name)(url) 
    File "C:\Python27\lib\urllib.py", line 463, in open_file 
    return self.open_local_file(url) 
    File "C:\Python27\lib\urllib.py", line 477, in open_local_file 
    raise IOError(e.errno, e.strerror, e.filename) 
IOError: [Errno 2] The system cannot find the path specified: '\\settings\\ads\\preferences?hl=en' 

gergin alıyorum ve gerçekten anlamıyorum hangi hata gerçekten burada

IOError: [Errno 2] The system cannot find the path specified: '\\settings\\ads\\preferences?hl=en' 

benim kodudur diye sormak için ....

+0

kimse ?????????? – user3162878

cevap

1

göreceli URL olabilir.

https://www.google.com/search?q=apple'da reklam görürseniz, href özniteliği '/ url? Q =/settings/ads/preferences' ile başlayan bir a öğesi vardır. the documentation of urllib.urlopen göre

,

If the URL does not have a scheme identifier, or if it has file: as its scheme identifier, this opens a local file (without universal newlines); otherwise it opens a socket to a server somewhere on the network.

Sen urllib.urlopen geçirmeden önce, URL mutlak yapmak için urlparse.urljoin kullanmalıdır.

+0

Teşekkürler. Cevapla çalıştıktan sonra cevap şöyle yazıyor: html = urlparse.urljoin (url) .read() ?? sonra hata alıyorum? – user3162878

+0

@ user3162878 Hayır. Yani, urllib.urlopen'e mutlak bir URL iletmelisiniz. Urlparse.urljoin 'q' mutlak yapmak için kullanın. Örneğin – pat

+0

, 'q = urlparse.urljoin (page.url, bağlantı [ 'href']. bölme ('/ URL? q =') [1] .split ('&') [0]) ' – pat

İlgili konular