|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import requests
- import bs4
- import re
- hd = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'}
- res = requests.get('http://sc.hkexnews.hk/TuniS/www.hkexnews.hk/sdw/search/mutualmarket_c.aspx?t=hk',headers = hd)
- html = res.text
- soup = bs4.BeautifulSoup(html,'html.parser')
- soup.prettify()
- node = soup.findAll('td',attrs = {'valign':'top','style':'arial12black'},string = re.compile(r'[\s\u4e00-\u9fa5]+\s'))
- print(node)
复制代码
运行结果: []
不知道哪里不对,请高手指点!
一个比较蠢的方法
- a=soup.findAll('td',valign='top')
- b=soup.findAll('td',valign='top',nowrap='nowrap')
- common=(set(a)^set(b))
- common_text=[i.text for i in common]
复制代码
这个可以避免使用正则表达式(其实是我正则不熟
另外公司名字有些是英文,你是想只匹配名字是中文的公司?
- common_text=[i.text.split('\r\n')[1].strip() for i in common]
复制代码
这是是格式化文本的
|
|