这是我的代码:
from selenium import webdriver
import pandas as pd
from lxml import etree
url = 'https://www.morningstar.com/stocks/xbsp/UGPA3/quote'
browser = webdriver.Chrome()
browser.get(url)
htmlpage = browser.page_source
doc = etree.HTML(htmlpage)
cap = doc.xpath(
'/html/body/div[1]/div/div/div[3]/main/div[2]/div/div/div[1]/sal-components/section/div/div/div[1]/div/div[2]/div/div/div/div[2]/ul/li[7]/div/div[2]/text()')
print(cap)
我正在尝试从网页上抓取市值。
在将htmlpage变量写入文件后,我发现问题是它没有下载整个页面。它下载2228 KB,而我的浏览器下载2664 KB .html文件以及一个不需要的文件夹。如果我使用浏览器手动保存页面并将其内容用作etree.HTML()的输入,则它可以工作,但是我想实现自动化。
答案 0 :(得分:0)
尝试
from matplotlib.backend_bases import MouseButton
...
class MyPaintWidget(QtWidgets.QWidget):
....
def _on_left_click(self, event):
if event.button == MouseButton.LEFT:
# draw circle
elif event.button == MouseButton.RIGHT:
# open context menu