600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > python bs4 提取网页表格里某个词_html - Python2 BeautifulSoup 提取网页中的表格数据及连接...

python bs4 提取网页表格里某个词_html - Python2 BeautifulSoup 提取网页中的表格数据及连接...

时间:2023-01-09 02:51:39

相关推荐

python bs4 提取网页表格里某个词_html - Python2 BeautifulSoup 提取网页中的表格数据及连接...

问 题

网址:/ce...

要做的是提取网页中的表格数据(如:板块名称,及相应链接下的所有个股,依然是个表格)

暂时只写了这些代码:

import urllib2

from bs4 import BeautifulSoup

req=urllib2.Request.(url)

page=urllib2.urlopen(req)

soup=BeautifulSoup(page)

table = soup.find("table")

但是table里面没有内容,也就是完全没找到,这是怎么回事啊。po是小白,希望大神们可以多多指教,谢谢!

解决方案

# coding:utf-8

import requests

r = requests.get('/EM_FinanceNumericApplication/JS.aspx?type=CT&cmd=C._BKGN&sty=FPGBKI&st=c&sr=-1&p=1&ps=5000&token=7bc05d0d4c3c22ef9fca8c2a912d779c&v=0.12043042036331286')

data = [_.decode('utf-8').split(',') for _ in eval(r.text)]

url = '/center/list.html#28003{}_0_2'

lst = [(url.format(_[1].replace('BK0', '')), _[2]) for _ in data]

print lst

扫一扫关注IT屋

微信公众号搜索 “ IT屋 ” ,选择关注与百万开发者在一起

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。