Jump to content
fallen_angel

[Python]Site scraping

Recommended Posts

Am reusit sa fac ceva, sper doar sa poti adapta pentru ce ai tu nevoie(vezi ca incarcarea pagini cu wx.html2.WebView dureaza cateva secunde, si de asemenea implementarea webView depinde de sistemul de operare.

Pe windows e implementat sa foloseasca dll-urile IE

Pe linux foloseste webKitGTK+

Pe macos foloseste OSxWebKit

iti postez un mic exemplu de test(probabil are vreo 2 erori + ca ai un main loop and stuff.

Pentru a putea implementa instantia webview ai nevoie de un frame parinte care sa il tina, insa nu e obligatoriu sa il si arati(cum fac eu).

Output-ul de la self.brsr.GetPageText este sub forma de string, si poti face pe el, orice operatie.

import wx

import wx.html2

import wx

class Example(wx.Frame):

def __init__(self, *args, **kw):

super(Example, self).__init__(*args, **kw)

self.InitUI()

def InitUI(self):

self.brsr = wx.html2.WebView.New(self)

self.brsr.LoadURL('http://www.auction.com/search?search=deltona+fl&auction_type=residential')

self.Bind(wx.html2.EVT_WEBVIEW_LOADED, self.OnLoaded)

def OnMove(self, e):

x, y = e.GetPosition()

self.st1.SetLabel(str(x))

self.st2.SetLabel(str(y))

def OnLoaded(self, e):

if(not self.brsr or self.brsr.IsBusy()):

return

print self.brsr.GetPageText()

def main():

ex = wx.App()

Example(None)

ex.MainLoop()

if __name__ == '__main__':

main()

  • Upvote 1
Link to comment
Share on other sites

Mersi nedo. E o solu?ie :)

Între timp am g?sit o alt? metod? de rezolvare, folosind Selenium* ?i PhantomJS.


from selenium import webdriver

URL = 'URL_UL_DORIT'
browser = webdriver.PhantomJS("phantomjs-1.9.7-windows\phantomjs.exe")
browser.get(URL)
html = browser.page_source.encode('utf8')

browser.quit()

Linia a 3-a: Constructorul de la PhantomJS trebuie s? primeasc? path-ul c?tre binarul PhantomJS pe care îl downloada?i de pe site sau dac? sunte?i pe Linux**, îl g?si?i în repository (cel pu?in pe Ubuntu).

*Selenium se instaleaz? cu pip install selenium .

**Evident path-ul transmis în constructor trebuie modificat. Parc? "/usr/bin/phantomjs" e dac? bine îmi aduc aminte.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...