|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import requests
- import bs4
- 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.find('td',attrs = {'class':'arial12black'},string = '长和')
- print(node)
-
复制代码
运行结果为None,为何找不到含有字符串"长和"的td标签?
- >>> a
- <td class="arial12black" valign="top">
- 长和
- </td>
- >>> b=str(a)
- >>> b
- '<td class="arial12black" valign="top">\r\n 长和\r\n </td>'
复制代码
- 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.find('td',attrs = {'class':'arial12black'},string = re.compile('长和'))
- print(node)
-
复制代码
|
|