response = requests.get(url)
html = response.text
#Find all the tags in which the data is stored.
soup = BeautifulSoup(html, 'lxml')
texts = soup.findAll("rect")
final = []
for each in texts:
names = each.get('onmouseover')
try:
q = re.findall(r"'(.*?)'", names)
final.append(q[0])
except Exception as e:
print(e)
#The details are appended to the final variable
url=”https://index.minfin.com.ua/ua/economy/index/svg.php?indType=1&;fromYear=2010和acc=1“
您将按如下方式加载HTML:
然后,您将使用此HTML创建BeatifulSoup对象
在此之后,如何解析出您想要的内容通常是非常主观的。候选代码可能变化很大。我就是这样做的:
使用BeautifulSoup,我解析了所有的“rect”,并检查该rect中是否存在“onmouseover”
从下图中可以看到,我刮取了
onmouseover=
部分,得到了那些02.2015 155,1
部分下面是
yx_points
现在的样子:[['12.2009', '100,0'], ['01.2010', '101,8'], ['02.2010', '103,7'], ...]
相关问题 更多 >
编程相关推荐