I'm a newbie to scraping. I'm trying to scrape the value from this site with button Buy Now.
Option I've tried is:
from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QUrl
from PyQt4.QtWebKit import QWebPage
class Client(QWebPage):
def __init__(self):
self.app = QApplication(sys.argv)
QWebPage.__init__(self)
# self.loadFinished.connect(self.on_page_load)
# self.mainFrame().load(QUrl(url))
# self.app.exec_()
def on_page_load(self):
self.app.quit()
def mypage(self, url):
self.loadFinished.connect(self.on_page_load)
self.mainFrame().load(QUrl(url))
self.app.exec_()
client_response = Client()
def parse(url): # OSRS + RS3
client_response.mypage(url)
source = client_response.mainFrame().toHtml()
soup = BeautifulSoup(source, 'html.parser')
osrs_text = soup.findAll('input', attrs={'type': 'number'})
quantity = (osrs_text[0])['min']
final = 0
if(quantity == '1'):
final_osrs = round(float(soup.findAll('span', attrs={'id':'goldprice'})[0].text),3)
print(final_osrs)
else:
price = round(float(soup.findAll('span', attrs={'id':'goldprice'})[0].text),3)
final_rs3 = price/int(quantity)
print(final_rs3)
This approach is not good because it's taking too much time to scrape. I also tried Selenium Approach but that's also not needed at the moment.
Can u guys please suggest me the better way to scrape the value? . Any help will highly be appreciated. Thanks.
P.S: I tried this library because the content was dynamically generated.
Aucun commentaire:
Enregistrer un commentaire