尝试创建一个类似instagram的机器人。它可以正确打开firebox浏览器,找到instagram并正确登录。它还搜索我输入并浏览的标签,但是它不喜欢这些照片
def like_photo(self, hashtag):
driver = self.driver
driver.get("https://www.instagram.com/explore/tags/"+ hashtag +"/")
time.sleep(2)
for i in range (1,3):
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(2)
hrefs = driver.find_elements_by_tag_name('a')
pic_hrefs = [elem.get_attribute('href') for elem in hrefs]
pic_hrefs = [href for href in pic_hrefs if hashtag in href]
print(hashtag + ' photos: ' + str(len(pic_hrefs)))
for pic_href in pic_hrefs:
driver.get(pic_href)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
try:
driver.find_element_by_link_text("Like").click()
time.sleep(18)
except Exception as e:
time.sleep(2)
tryIG = InstagramBot("ueracct", "12345")
tryIG.login()
tryIG.like_photo('tag1')
尝试搜索照片并双击它
相关问题 更多 >
编程相关推荐