Skip to content

Instantly share code, notes, and snippets.

@potaycat
Created September 14, 2019 07:40
Show Gist options
  • Save potaycat/335ff3e89363e2b51c0d2414145debb2 to your computer and use it in GitHub Desktop.
Save potaycat/335ff3e89363e2b51c0d2414145debb2 to your computer and use it in GitHub Desktop.
one of my first encounter to the web. a recreate of Tom Scott's youtube privacy demo in a presentation of his
import urllib
import urllib2
from bs4 import BeautifulSoup
from lxml import etree
def main():
textToSearch = raw_input('tim video cho thuyet trinh: ')
query = urllib.quote(textToSearch)
url = "https://www.youtube.com/results?search_query=" + query
response = urllib2.urlopen(url)
html = response.read()
soup = BeautifulSoup(html)
htmlify(soup)
def htmlify(sup):
root = etree.Element('html')
a = etree.Element('body')
root.append(a)
b = etree.Element('text')
b.text = "Danh cho phan dan chung"
a.append(b)
etree.SubElement(b, 'br')
etree.SubElement(b, 'br')
for vid in range(0,6):
linka = sup.findAll(attrs={'class':'yt-uix-tile-link'})[vid]
fr = etree.Element('iframe')
fr.set('width',"420")
fr.set('height',"260")
fr.set('src', 'https://www.youtube.com/embed/' + linka['href'][9:9+11] + '?autoplay=1&vq=tiny' )
etree.SubElement(fr, 'lazyWorkaround')
a.append(fr)
string = etree.tostring(root, pretty_print=True)
text_file = open("ytSrchPull.html", "w")
text_file.write(string)
text_file.close()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment