<jupyter_start><jupyter_text>print(header[0]) print(header[0].text)<jupyter_code>print(header[0])
print(header[0].text)
#select id user #
atitile=soup.select("#title")
print(atitile)
#select class link #
atitile=soup.select(".link")
#link array
print(atitile)
# print link href
print(atitile[0]['href'])
#select all a element (link)
alinks=soup.select('a')
for link in alinks:
    print(link)
    #print(link['href'])
#sample for get attribute
a='<a href="#" abc=1 bcd=2> simple link</a>'
soup2=BeautifulSoup(a)
print(soup2.select('a')[0])
print(soup2.select('a')[0]['abc'])
# print sina news title and it's href 
soup=BeautifulSoup(res.text)
for news in soup.select('.news-2'):
    for news1 in news.select('li'):
        print(news1.text)
        print(news1.select('a')[0]['href'])
#    if(len(news.select('li'))>0):
#        h2=news.select('li')[0].text
#        #time=news.select('.time')[0].text
#        a=news.select('a')[0]['href']
#        print(h2,a)
'''
another sample for youku 
'''
# new sample for youku wangyubing 
import requests
from bs4 import BeautifulSoup
newsurl="http://i.youku.com/i/UNDA0NDIzMDgw/videos?spm=a2hzp.8244740.0.0"
res=requests.get(newsurl)
res.encoding='UTF-8'
print(res)
#print(res.text)
print(type(res))
soup=BeautifulSoup(res.text)
#print(soup)
#select by class videos-list
news = soup.select('.items')

print(news[0].select('.va')[0].select('.v-meta-title')[0].select('a')[0].text)
print(news[0].select('.va')[0].select('.v-meta-title')[0].select('a')[0]['href'])
for news in soup.select('.items'):
    for news1 in news.select('.va'):
        #print(news1.select('.v-meta-title')[0].select('a')[0].text)
        print(news1.select('.v-meta-title')[0].select('a')[0]['href'])
        #print(news1.select('a')[0]['href'])
#sample of regular use
import re

newsurl='http://news.sina.com.cn/c/nd/2016-08-20/doc-ifxvctcc8121090.shtml'
m=re.search('doc-i(.*).shtml', newsurl)
print(m.group(1))<jupyter_output>fxvctcc8121090
{'fraction_non_alphanumeric': 0.22103113833588567, 'fraction_numerical': 0.03879530372639101, 'mean_word_length': 5.24203821656051, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '558832', 'license': 'Apache-2.0', 'n_tokens_mistral': 817, 'n_tokens_neox': 793, 'n_words': 119, 'path': '163SpiderLesson.ipynb', 'repo_name': 'jettom/JtSpider', 'size': '1959'}