使用urllib獲取網頁**
使用etree解析網頁資料並使用xpath找到想要的內容
傳送
# 獲取每日一句英語
from lxml import etree
from urllib.request import urlopen
import urllib
import itchat as ic
## 位址
url =
''req = urllib.request.request(url)
html = urlopen(req)
.read(
)# 解析網頁資料
html = etree.html(html)
# 獲取想要的內容
result = html.xpath(
'.//div[@id="senten_move"]/p/text()'
)# 英文句子
english = result[0]
# 翻譯
chinese = result[1]
all=
'每日一句:\n'
+ english +
'\n'
+ chinese
ic.auto_login(
)name =
input()
friends = ic.search_friends(name)
friendname = friends[0]
['username'
]# 傳送訊息
ic.send(
all, friendname)
python day3 爬取每日一句
import requests import re from bs4 import beautifulsoup url 每一期的鏈結共同的部分 words 0 1800 定義乙個長度為1800的列表,用來儲存每一句話,並初始化為全 0 for i in range 0,100 s str i 數字型...
每日一句 2014 8 26
when life gets hard and you want to give up,remember that life is full of ups and downs,and without the downs,the ups would mean nothing 當生活很艱難,你想要放棄的...
每日一句 2014 9 1
people with goals succeed because they know where they re going 有目標的人能夠成功,因為他們知道他們要去哪 people with goals succeed because they know where they re going ...