我正在使用这行代码使用 matplotlib 创建跨图形的垂直跨度。
matplotlib.pyplot.axvspan(datetime.datetime.strptime("09-10-2015", '%d-%m-%Y'), datetime.datetime.strptime(now.strftime("%d-%m-%Y"), '%d-%m-%Y'), fill=True, linewidth=0, color='r')
Run Code Online (Sandbox Code Playgroud)
不过,我希望它能够遍历图表以隐藏图表上的线。目前它只是这样做。
如何使 axvspan 的填充变为实心且不透明?
我需要一个解决方案来使用 Python3 搜索 html 文件并检索<a>页面上的所有链接。然后将抓取的值附加到具有相邻 href (url) 的字典中。
这是我已经尝试过的。
import urllib3
import re
http = urllib3.PoolManager()
my_url = "https://in.finance.yahoo.com/q/h?s=AAPL"
a = http.request("GET",my_url)
html = a.data
links = re.finditer(' href="?([^\s^"]+)', html)
for link in links:
print(link)
Run Code Online (Sandbox Code Playgroud)
我收到这个错误...
TypeError: can't use a string pattern on a bytes-like object
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助。
我也尝试过lxml...
links = lxml.html.parse("http://www.google.co.uk/?gws_rd=ssl#q=apple+stock&tbm=nws").xpath("//a/@href")
for link in links:
print(link)
Run Code Online (Sandbox Code Playgroud)
结果没有显示所有链接,我不知道为什么。
更新:
新代码 =>
def news_feed(self, stock):
http = urllib3.PoolManager()
my_url = "https://in.finance.yahoo.com/q/h?s="+stock
a = http.request("GET",my_url)
html = a.data.decode('utf-8')
xml = fromstring(html, …Run Code Online (Sandbox Code Playgroud)