最近在忙于找工作,閑暇之余,也找點爬蟲項目練練手,寫寫代碼,知道自己是個菜鳥,但是要多加練習,書山有路勤為徑。各位爺有測試坑可以給我介紹個啊,自動化,功能,接口都可以做。
首先呢,我們明確需求,很多同學呢,有事沒事就想看看一些技術,比如我想看看JQuery的語法呢,可是我現在沒有網絡,手機上也沒有電子書,真的讓我們很難受,那么別著急啊,你這需求我在這里滿足你,首先呢,你的需求是獲取JQuery的語法的,那么我在看到這個需求,我有響應的網站那么我們接下來去分析這個網站。http://www.w3school.com.cn/jquery/jquery_syntax.asp 這是語法url, http://www.w3school.com.cn/jquery/jquery_intro.asp 這是簡介的url,那么我們拿到很多的url分析到,我們的http://www.w3school.com.cn/jquery是相同的,那么我們在來分析在界面怎么可以獲取得到這些,我們可以看到右面有相應的目標欄,那么我們去分析下
我們來看下這些鏈接,。我們可以吧這些鏈接和http://www.w3school.com.cn拼接到一起。然后組成我們新的url,
上代碼
import urllib.requestfrom bs4 import BeautifulSoup import timedef head(): headers={ 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0' } return headersdef parse_url(url): hea=head() resposne=urllib.request.Request(url,headers=hea) html=urllib.request.urlopen(resposne).read().decode('gb2312') return htmldef url_s(): url='http://www.w3school.com.cn/jquery/index.asp' html=parse_url(url) soup=BeautifulSoup(html) me=soup.find_all(id='course') m_url_text=[] m_url=[] for link in me: m_url_text.append(link.text) m=link.find_all('a') for i in m: m_url.append(i.get('href')) for i in m_url_text: h=i.encode('utf-8').decode('utf-8') m_url_text=h.split('/n') return m_url,m_url_text
這樣我們使用url_s這個函數就可以獲取我們所有的鏈接。
['/jquery/index.asp', '/jquery/jquery_intro.asp', '/jquery/jquery_install.asp', '/jquery/jquery_syntax.asp', '/jquery/jquery_selectors.asp', '/jquery/jquery_events.asp', '/jquery/jquery_hide_show.asp', '/jquery/jquery_fade.asp', '/jquery/jquery_slide.asp', '/jquery/jquery_animate.asp', '/jquery/jquery_stop.asp', '/jquery/jquery_callback.asp', '/jquery/jquery_chaining.asp', '/jquery/jquery_dom_get.asp', '/jquery/jquery_dom_set.asp', '/jquery/jquery_dom_add.asp', '/jquery/jquery_dom_remove.asp', '/jquery/jquery_css_classes.asp', '/jquery/jquery_css.asp', '/jquery/jquery_dimensions.asp', '/jquery/jquery_traversing.asp', '/jquery/jquery_traversing_ancestors.asp', '/jquery/jquery_traversing_descendants.asp', '/jquery/jquery_traversing_siblings.asp', '/jquery/jquery_traversing_filtering.asp', '/jquery/jquery_ajax_intro.asp', '/jquery/jquery_ajax_load.asp', '/jquery/jquery_ajax_get_post.asp', '/jquery/jquery_noconflict.asp', '/jquery/jquery_examples.asp', '/jquery/jquery_quiz.asp', '/jquery/jquery_reference.asp', '/jquery/jquery_ref_selectors.asp', '/jquery/jquery_ref_events.asp', '/jquery/jquery_ref_effects.asp', '/jquery/jquery_ref_manipulation.asp', '/jquery/jquery_ref_attributes.asp', '/jquery/jquery_ref_css.asp', '/jquery/jquery_ref_ajax.asp', '/jquery/jquery_ref_traversing.asp', '/jquery/jquery_ref_data.asp', '/jquery/jquery_ref_dom_element_methods.asp', '/jquery/jquery_ref_core.asp', '/jquery/jquery_ref_prop.asp'], ['jQuery 教程', '', 'jQuery 教程', 'jQuery 簡介', 'jQuery 安裝', 'jQuery 語法', 'jQuery 選擇器', 'jQuery 事件', '', 'jQuery 效果', '', 'jQuery 隱藏/顯示', 'jQuery 淡入淡出', 'jQuery 滑動', 'jQuery 動畫', 'jQuery stop()', 'jQuery Callback', 'jQuery Chaining', '', 'jQuery HTML', '', 'jQuery 獲取', 'jQuery 設置', 'jQuery 添加', 'jQuery 刪除', 'jQuery CSS 類', 'jQuery css()', 'jQuery 尺寸', '', 'jQuery 遍歷', '', 'jQuery 遍歷', 'jQuery 祖先', 'jQuery 后代', 'jQuery 同胞', 'jQuery 過濾', '', 'jQuery AJAX', '', 'jQuery AJAX 簡介', 'jQuery 加載', 'jQuery Get/Post', '', 'jQuery 雜項', '', 'jQuery noConflict()', '', 'jQuery 實例', '', 'jQuery 實例', 'jQuery 測驗', '', 'jQuery 參考手冊', '', 'jQuery 參考手冊', 'jQuery 選擇器', 'jQuery 事件', 'jQuery 效果', 'jQuery 文檔操作', 'jQuery 屬性操作', 'jQuery CSS 操作', 'jQuery Ajax', 'jQuery 遍歷', 'jQuery 數據', 'jQuery DOM 元素', 'jQuery 核心', 'jQuery 屬性', '', ''])
新聞熱點
疑難解答