所以我的数组包含了这些数据
Abonnenten = ["https://www.instagram.com/vivksj/",
"https://www.instagram.com/aaalink/",
"https://www.instagram.com/haanannnnna/",
"https://www.instagram.com/tiigergirlxofical/",
"https://www.instagram.com/patriiciaa.015/",
"https://www.instagram.com/itss_leonie_/",
"https://www.instagram.com/patriciawk/",
"https://www.instagram.com/taelly.scr/",
"https://www.instagram.com/mozzhliana/",
"https://www.instagram.com/mialecdron/"]由于数据保护,我更改了用户名,但您得到了示例。在我的代码中,我想浏览一些选定的instagram用户。如果他们的snapchat像这样链接在他们的个人简历中:
for i in range(len(Abonnenten)):
driver.get(Abonnenten[i])
# get the text from their instagram bio
try:
wait = WebDriverWait(driver, 10)
bio = wait.until(EC.presence_of_element_located((By.XPATH, "//div[@class='-vDIg']/span"))).text
Snapnames = list.append(bio)
print(Snapnames)在这里,我想尝试获取我的应用程序打印出来的所有snapchat名称。但我搞不懂。
# check if text contains "snapchat"
if ("snapchat" in bio):
# split the instagram bio by newline char to get line with snapchat name
bio_lines = bio.split("\n")
# parse over the instagram bio to find snapchat username
for line in bio_lines:
# if we find the line with username, strip out text to get the username
if ("Snapchat:" in line):
#snapchat_username = []
snapchat_username = line.replace[("Snapchat:", "")]
# you probably need to do something here to save to file
print(snapchat_username)尽管这些代码行都有注释,但我不知道它们是做什么的,也不知道它们是否工作。
# case: the user does not have a bio, so just move on to the next one
except TimeoutException:
continue
i = i + 1代码的最后一行应该是自我解释。再一次,我想在instagram用户的个人简历中搜索的snapchat名称,如果他们有这个名字,它会将其保存到一个列表或数组中,这样我就可以把它作为一个文件提供出来,或者打印出来。(我用发色器)
发布于 2019-11-20 19:41:39
这应该会让你开始,它会创建一个用户名列表及其相关的bio。
import requests
profile_links = ["https://www.instagram.com/vivksj/",
"https://www.instagram.com/aaalink/",
"https://www.instagram.com/haanannnnna/",
"https://www.instagram.com/tiigergirlxofical/",
"https://www.instagram.com/patriiciaa.015/",
"https://www.instagram.com/itss_leonie_/",
"https://www.instagram.com/patriciawk/",
"https://www.instagram.com/taelly.scr/",
"https://www.instagram.com/mozzhliana/",
"https://www.instagram.com/mialecdron/"]
profile_data_list = []
for curr_profile_url in profile_links:
req_res = requests.get(curr_profile_url + '?__a=1')
if req_res.status_code != 200:
print(f'Error status code {req_res.status_code} for url {curr_profile_url}')
else:
json_res = req_res.json()
json_user_portion = json_res['graphql']['user']
username = json_user_portion['username']
profile_data_list.append((username, json_user_portion))
profile_bio_list = [(curr_username, curr_data['biography']) for curr_username, curr_data in profile_data_list]profile_bio_list看起来是这样的:
[('vivksj',
"I just don't walk on the clouds of my dreams,I turn them into reality..."),
('aaalink', ''),
('itss_leonie_',
'❤️14 y/o❤️\n'
'15.8 B-day❤️\n'
'@itss_celia_ ❤️\n'
'@itss_maria_4 ❤️\n'
'@leonie__prv_'),
('patriciawk', '')]https://stackoverflow.com/questions/58943644
复制相似问题