Advertisement
johnmahugu

python - word press attachment

Jul 8th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. #!/usr/bin/python
  2. import requests
  3. from BeautifulSoup import BeautifulSoup
  4. #Variables to modify
  5. URL="http://localhost/wordpress/"
  6. start_count=0
  7. end_count=1000
  8. #don't modify below this
  9. for n in range(start_count,end_count):
  10.   exp_url=URL+"?attachment_id=" + str(n)
  11.   r=requests.get(exp_url,allow_redirects=False)
  12.   if 200 == r.status_code:
  13.     soup=BeautifulSoup(r.text)
  14.     #image
  15.     each_div=soup.find('div',{'class':'attachment'})
  16.     if each_div != None:
  17.       tar_img=each_div.find('a').find('img')['src']
  18.       tar_link=each_div.find('a')['href']
  19.       if tar_img == "":
  20.         print str(n) + " : " + tar_link
  21.       else:
  22.         print str(n) + " : " + tar_img
  23.       tar_img=""
  24.     else:
  25.     #all others (tested with pdf,html and some more)
  26.       each_div=soup.find('p',{'class':'attachment'})
  27.       print str(n) + " : " + each_div.find('a')['href']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement