#該操作主要是以本地ip對mysql進行訪問,
整理得有點亂,多多包涵囉~~~
def Spider():
# 懶地註釋囉!自己查吧
import requests
from lxml import etree
import re
# 模擬請求頭
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36"
}
# 抓取網址,請求頭
r = requests.get('http://www.seputu.com/', headers=headers)
html = etree.HTML(r.text)
rows = []
titall = html.xpath('//*[@class="mulu"]')
for tit in titall:
h2 = tit.xpath('.//div[@class="mulu-title"]/center/h2/text()')
# 判斷是否存在內容
if len(h2):
h2tit = h2
a_s = tit.xpath('./div[@class="box"]/ul/li/a')
for a in a_s:
href = a.xpath('./@href')[0]
tits = a.xpath('./@title')[0]
# 匹配所有
pattern = re.compile(r'\s*