自媒体测试爬虫 图片文字上传 发布图文

 

 

 

 

 

 

 

 

 

from selenium import webdriver
from time import sleep
import time
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox(
executable_path='C:\\Users\\sas\\PycharmProjects\\py_win_to_unix\\crontab_chk_url\\personas\\trunk\plugins\spider\\geckodriver.exe')

url_seed = 'https://sso.toutiao.com/'

browser.get(url_seed)

xp_newpage = '/html/body/div/div/div[2]/div/div/div/ul/li[2]'
browser.find_element_by_xpath(xp_newpage).click()
myid, mypwd = '123@sina.cn', '123'
js = '%s%s%s' % ('document.getElementById("userId").value="', myid, '"')
browser.execute_script(js)
js = '%s%s%s' % ('document.getElementById("passwd").value="', mypwd, '"')
browser.execute_script(js)
xp_newpage = '//*[@id="outer"]/div/div[2]/form/div/div[2]/div/p/a[1]'
browser.find_element_by_xpath(xp_newpage).click()

sleep(8)

for i in range(18):
sleep(1)
try:
xp_newpage = '/html/body/div/div[2]/div[2]/div[1]/div/div/div/div/textarea'
browser.find_element_by_xpath(xp_newpage).click()

# 实际写入内容mytxt
mytxt = '%s%s' % (
'今天大晴天打篮球打篮球-------------------------', time.strftime('%Y%m%d_%H%M%S', time.localtime(time.time())))
js = '%s%s%s' % ('document.getElementsByTagName("textarea")[0].value="', mytxt, '"')
browser.execute_script(js)

# 需要键盘事件 反爬虫
browser.find_element_by_xpath(xp_newpage).send_keys(Keys.SPACE)
browser.find_element_by_xpath(xp_newpage).send_keys(mytxt)
browser.find_element_by_xpath(xp_newpage).send_keys(Keys.CONTROL, 'a')
browser.find_element_by_xpath(xp_newpage).send_keys(Keys.CONTROL, 'x')
browser.find_element_by_xpath(xp_newpage).send_keys(Keys.CONTROL, 'v')

sleep(3)
xp_newpage = '/html/body/div/div[2]/div[2]/div[1]/div/ul'
browser.find_element_by_xpath(xp_newpage).click()
sleep(1)
xp_newpage = '/html/body/div/div[2]/div[2]/div[1]/div/div/div/div/div[1]/div[2]/a'
browser.find_element_by_xpath(xp_newpage).click()
except Exception as e:
print(e)



<div class="bui-box upload-footer">
<div class="bui-left"><span ga_event="user_ugc_img_open" class="show-image-uploader show-uploader"><i
class="bui-icon icon-pic_tool"
style="font-size: 20px; color: rgb(237, 64, 64);"></i> <span>添加图片</span></span> <span class="checkbox-wrap"><span
class="checkbox"><i class="bui-icon icon-check"
style="font-size: 10px; color: rgb(255, 255, 255);"></i></span> <span>发布长文</span></span>
</div>
<div class="bui-right"><span class="msg-tip"></span> <a class="upload-publish">发布</a></div>
</div>

<div class="uploader-popup" style="">
<div class="imgUploadBox"><p class="uploader-title">本地上传</p>
<p class="uploader-meta">共 0 张,还能上传 9 张</p> <i class="bui-icon close-popup icon-close_small"></i>
<div class="bui-box upload-box">
<form style="display: none;"><input id="fileElem" type="file" accept="image/*" multiple="multiple"></form>
<ul class="upload-img-list">
<li ga_event="user_ugc_img_upload" class="upload-img-item upload-img-add"><i
class="bui-icon icon-add_small" style="font-size: 30px; color: rgb(221, 221, 221);"></i></li>
</ul>
</div>
</div>
</div>





<div class="bui-box upload-footer">
<div class="bui-left"><span ga_event="user_ugc_img_open" class="show-image-uploader show-uploader"><i
class="bui-icon icon-pic_tool"
style="font-size: 20px; color: rgb(237, 64, 64);"></i> <span>添加图片</span></span> <span class="checkbox-wrap"><span
class="checkbox"><i class="bui-icon icon-check"
style="font-size: 10px; color: rgb(255, 255, 255);"></i></span> <span>发布长文</span></span>
</div>
<div class="bui-right"><span class="msg-tip"></span> <a class="upload-publish">发布</a></div>
</div>

<div class="uploader-popup" style="">
<div class="imgUploadBox"><p class="uploader-title">本地上传</p>
<p class="uploader-meta">共 1 张,还能上传 8 张</p> <i class="bui-icon close-popup icon-close_small"></i>
<div class="bui-box upload-box">
<form style="display: none;"><input id="fileElem" type="file" accept="image/*" multiple="multiple"></form>
<ul class="upload-img-list">
<li class="upload-img-item">
<div class="img-wrap"><img src="http://p3.pstatp.com/origin/54dd00017b751f1aef19"></div>
<i class="bui-icon remove-img icon-close_small"></i></li>
<li ga_event="user_ugc_img_upload" class="upload-img-item upload-img-add"><i
class="bui-icon icon-add_small" style="font-size: 30px; color: rgb(221, 221, 221);"></i></li>
</ul>
</div>
</div>
</div>







from selenium import webdriver
from time import sleep
import time
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox(
executable_path='C:\\Users\\sas\\PycharmProjects\\py_win_to_unix\\crontab_chk_url\\personas\\trunk\plugins\spider\\geckodriver.exe')

url_seed = 'https://sso.toutiao.com/'

browser.get(url_seed)

xp_newpage = '/html/body/div/div/div[2]/div/div/div/ul/li[2]'
browser.find_element_by_xpath(xp_newpage).click()
myid, mypwd = '123@sina.cn', '123'
js = '%s%s%s' % ('document.getElementById("userId").value="', myid, '"')
browser.execute_script(js)
js = '%s%s%s' % ('document.getElementById("passwd").value="', mypwd, '"')
browser.execute_script(js)
xp_newpage = '//*[@id="outer"]/div/div[2]/form/div/div[2]/div/p/a[1]'
browser.find_element_by_xpath(xp_newpage).click()

sleep(8)

for i in range(18):
sleep(1)
try:
xp_newpage = '/html/body/div/div[2]/div[2]/div[1]/div/div/div/div/textarea'
browser.find_element_by_xpath(xp_newpage).click()

# 实际写入内容mytxt
mytxt = '%s%s' % (
'今天大晴天打篮球打篮球-------------------------', time.strftime('%Y%m%d_%H%M%S', time.localtime(time.time())))
js = '%s%s%s' % ('document.getElementsByTagName("textarea")[0].value="', mytxt, '"')
browser.execute_script(js)

# 需要键盘事件 反爬虫
browser.find_element_by_xpath(xp_newpage).send_keys(Keys.SPACE)
browser.find_element_by_xpath(xp_newpage).send_keys(mytxt)
browser.find_element_by_xpath(xp_newpage).send_keys(Keys.CONTROL, 'a')
browser.find_element_by_xpath(xp_newpage).send_keys(Keys.CONTROL, 'x')
browser.find_element_by_xpath(xp_newpage).send_keys(Keys.CONTROL, 'v')

sleep(3)

xp_newpage = '/html/body/div/div[2]/div[2]/div[1]/div/div/div/div/div[1]/div[1]/span[1]/span'
browser.find_element_by_xpath(xp_newpage).click()

upload = browser.find_element_by_id('fileElem')

for ii in range(1, 4, 1):
try:
img = '%s%s%s' % ('d:\\toutiao_timg', str(ii), '.png')
upload.send_keys(img)
          sleep(1)
except Exception as ee:
print(ee)

xp_newpage = '/html/body/div/div[2]/div[2]/div[1]/div/ul'
browser.find_element_by_xpath(xp_newpage).click()
sleep(1)
xp_newpage = '/html/body/div/div[2]/div[2]/div[1]/div/div/div/div/div[1]/div[2]/a'
browser.find_element_by_xpath(xp_newpage).click()
except Exception as e:
print(e)





 

 


posted @ 2018-01-03 17:53  papering  阅读(602)  评论(0编辑  收藏  举报