<?xml version="1.0"?>
<rss version="2.0">
   <channel>
      <title>筆記 by 606-15-王昱智</title>
      <link>https://padlet.com/leo0227/zdco33t1aau31ea0</link>
      <description></description>
      <language>en-us</language>
      <pubDate>2024-06-02 22:42:44 UTC</pubDate>
      <lastBuildDate>2024-06-03 07:53:20 UTC</lastBuildDate>
      <webMaster>hello@padlet.com</webMaster>
      <image>
         <url></url>
      </image>
      <item>
         <title>下載套件</title>
         <author>leo0227</author>
         <link>https://padlet.com/leo0227/zdco33t1aau31ea0/wish/3015623321</link>
         <description><![CDATA[<div><br></div><div>requert</div><div>建立適當的 HTTP 請求，透過 HTTP 請求從網頁伺服器下載指定的資料<br><br>io</div><div>負責開啟檔案、關閉檔案的套件</div><div><br></div><div>time</div><div>負責處理時間上的運算，可以計算爬蟲花了多久</div>]]></description>
         <enclosure url="" />
         <pubDate>2024-06-02 22:44:48 UTC</pubDate>
         <guid>https://padlet.com/leo0227/zdco33t1aau31ea0/wish/3015623321</guid>
      </item>
      <item>
         <title>處理反爬機制</title>
         <author>leo0227</author>
         <link>https://padlet.com/leo0227/zdco33t1aau31ea0/wish/3016017921</link>
         <description><![CDATA[<div><br><br>許多網站有防止爬蟲的機制，可以通過模擬人類行為來避免被檢測到。<br><br>模擬User-Agent<br><br>headers = {<br>&nbsp; &nbsp; 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'<br>}<br>response = requests.get('https://example.com', headers=headers)<br><br>使用Cookies<br><br>session = requests.Session()<br>session.headers.update(headers)<br>session.get('https://example.com')&nbsp; # 初始化會話，獲取初始Cookies<br><br>response = session.get('https://example.com/some-page')<br><br>使用代理<br><br>proxies = {<br>&nbsp; &nbsp; 'http': 'http://10.10.1.10:3128',<br>&nbsp; &nbsp; 'https': 'http://10.10.1.10:1080',<br>}<br>response = requests.get('https://example.com', headers=headers, proxies=proxies)</div>]]></description>
         <enclosure url="" />
         <pubDate>2024-06-03 04:57:39 UTC</pubDate>
         <guid>https://padlet.com/leo0227/zdco33t1aau31ea0/wish/3016017921</guid>
      </item>
      <item>
         <title>處理動態加載內容</title>
         <author>leo0227</author>
         <link>https://padlet.com/leo0227/zdco33t1aau31ea0/wish/3016018773</link>
         <description><![CDATA[<div><br><br>一些網站使用JavaScript動態加載內容，這時候可以使用Selenium或Pyppeteer來模擬瀏覽器行為。<br><br>使用Selenium<br><br>from selenium import webdriver<br>from selenium.webdriver.chrome.service import Service<br>from selenium.webdriver.common.by import By<br>from selenium.webdriver.chrome.options import Options<br>from selenium.webdriver.chrome.service import Service as ChromeService<br><br># 設置瀏覽器選項<br>chrome_options = Options()<br>chrome_options.add_argument("--headless")&nbsp; # 啟動無頭模式<br><br># 初始化WebDriver<br>service = ChromeService(executable_path='/path/to/chromedriver')<br>driver = webdriver.Chrome(service=service, options=chrome_options)<br><br># 訪問目標網站<br>driver.get('https://example.com')<br><br># 等待頁面加載完成<br>driver.implicitly_wait(10)<br><br># 提取動態加載的內容<br>elements = driver.find_elements(By.TAG_NAME, 'h1')<br>for element in elements:<br>&nbsp; &nbsp; print(element.text)<br><br># 關閉WebDriver<br>driver.quit()</div>]]></description>
         <enclosure url="" />
         <pubDate>2024-06-03 04:58:25 UTC</pubDate>
         <guid>https://padlet.com/leo0227/zdco33t1aau31ea0/wish/3016018773</guid>
      </item>
      <item>
         <title>1</title>
         <author>leo0227</author>
         <link>https://padlet.com/leo0227/zdco33t1aau31ea0/wish/3016019712</link>
         <description><![CDATA[<div><br>	1.	發送HTTP請求：<br>使用requests庫來發送一個HTTP請求並獲取網頁的HTML內容。<br><br>import requests<br><br>url = 'https://example.com'<br>response = requests.get(url)<br>html_content = response.text<br><br><br>	2.	解析HTML：<br>使用BeautifulSoup來解析HTML內容，以便提取需要的信息。<br><br>from bs4 import BeautifulSoup<br><br>soup = BeautifulSoup(html_content, 'lxml')<br><br><br>	3.	提取數據：<br>使用BeautifulSoup的各種方法來查找和提取數據，例如find_all、find、select等。<br><br># 查找所有的標題<br>titles = soup.find_all('h1')<br>for title in titles:<br>&nbsp; &nbsp; print(title.get_text())<br><br># 使用CSS選擇器<br>links = soup.select('a')<br>for link in links:<br>&nbsp; &nbsp; print(link['href'])<br><br><br>	4.	保存數據：<br>可以使用pandas來保存數據到CSV文件中。<br><br>import pandas as pd<br><br>data = {'Title': [title.get_text() for title in titles]}<br>df = pd.DataFrame(data)<br>df.to_csv('titles.csv', index=False)</div>]]></description>
         <enclosure url="" />
         <pubDate>2024-06-03 04:59:15 UTC</pubDate>
         <guid>https://padlet.com/leo0227/zdco33t1aau31ea0/wish/3016019712</guid>
      </item>
   </channel>
</rss>
