2
Answers

extracting same result using selenium

Ilyas Zahir

Ilyas Zahir

6y
175
1
I'm extracting posts from instagram using selenium, so I get image src and its text. the problem is that while extracting it's scrape same src and different text for such post.

Here is my code
 
var options = new ChromeOptions(); options.AddArguments("--disable-gpu"); 
var driverService = ChromeDriverService.CreateDefaultService(); 
driverService.HideCommandPromptWindow = true; 
var dr = new ChromeDriver(driverService, options); 
for (int d = 0; d < listBox1.Items.Count; d++) {     
dr.Navigate().GoToUrl("https://www.instagram.com/" + listBox1.Items[d].ToString()); 
var number = dr.FindElementByClassName("_fd86t").Text; Thread.Sleep(100);    
 dr.FindElementByClassName("_si7dy").Click(); 
for (int s = 0; s < Convert.ToInt32(numericUpDown1.Value); s++) { 
Thread.Sleep(1000); 
if (dr.FindElements(By.XPath("/html/body/div[4]/div/div[2]/div/article/div[1]/div/div/div/div[2]/a")).Count != 0) {           
  dr.Keyboard.SendKeys(OpenQA.Selenium.Keys.Right); }
 else { 
var src = dr.FindElementByClassName("_2di5p").GetAttribute("src");
 var pra = dr.FindElementByClassName("_ezgzd").FindElement(By.TagName("span")).Text; 
this.Invoke(new MethodInvoker(delegate () {                 
dataGridView1.Rows.Add(src.ToString(), pra.ToString()); }));        
dr.Keyboard.SendKeys(OpenQA.Selenium.Keys.Right); } } }
 
Answers (2)